summaryrefslogtreecommitdiff
path: root/coverage/collector.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-01-18 13:25:49 -0500
committerNed Batchelder <ned@nedbatchelder.com>2015-01-18 13:25:49 -0500
commitb90e592e26da67372cb633150c49372799dc51bf (patch)
treed822e639649bd73b4c41d1d82a64bf457c477535 /coverage/collector.py
parent9298cc26cae698bd7e7ab0c0e0a8d0931d77f7e2 (diff)
downloadpython-coveragepy-b90e592e26da67372cb633150c49372799dc51bf.tar.gz
Collect all the nudgy environment checks into coverage.env
Diffstat (limited to 'coverage/collector.py')
-rw-r--r--coverage/collector.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/coverage/collector.py b/coverage/collector.py
index 39acd7b..ded6d92 100644
--- a/coverage/collector.py
+++ b/coverage/collector.py
@@ -2,6 +2,7 @@
import os, sys
+from coverage import env
from coverage.misc import CoverageException
from coverage.pytracer import PyTracer
@@ -11,23 +12,18 @@ try:
except ImportError:
# Couldn't import the C extension, maybe it isn't built.
if os.getenv('COVERAGE_TEST_TRACER') == 'c':
- # During testing, we use the COVERAGE_TEST_TRACER env var to indicate
- # that we've fiddled with the environment to test this fallback code.
- # If we thought we had a C tracer, but couldn't import it, then exit
- # quickly and clearly instead of dribbling confusing errors. I'm using
- # sys.exit here instead of an exception because an exception here
- # causes all sorts of other noise in unittest.
+ # During testing, we use the COVERAGE_TEST_TRACER environment variable
+ # to indicate that we've fiddled with the environment to test this
+ # fallback code. If we thought we had a C tracer, but couldn't import
+ # it, then exit quickly and clearly instead of dribbling confusing
+ # errors. I'm using sys.exit here instead of an exception because an
+ # exception here causes all sorts of other noise in unittest.
sys.stderr.write(
"*** COVERAGE_TEST_TRACER is 'c' but can't import CTracer!\n"
)
sys.exit(1)
CTracer = None
-try:
- import __pypy__
-except ImportError:
- __pypy__ = None
-
class Collector(object):
"""Collects trace data.
@@ -141,7 +137,8 @@ class Collector(object):
# A cache of the results from should_trace, the decision about whether
# to trace execution in a file. A dict of filename to (filename or
# None).
- if __pypy__ is not None:
+ if env.PYPY:
+ import __pypy__ # pylint: disable=import-error
# Alex Gaynor said:
# should_trace_cache is a strictly growing key: once a key is in
# it, it never changes. Further, the keys used to access it are