diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-01-18 13:25:49 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-01-18 13:25:49 -0500 |
commit | 8d60d392c5d9b00560c4a9418902f12126dae125 (patch) | |
tree | c6634c5c0b940a32c1fb0afb36b4a928a91f3304 /coverage/collector.py | |
parent | 0d0836309b6354a07fb09cd8d28b309b6c8dba6c (diff) | |
download | python-coveragepy-git-8d60d392c5d9b00560c4a9418902f12126dae125.tar.gz |
Collect all the nudgy environment checks into coverage.env
Diffstat (limited to 'coverage/collector.py')
-rw-r--r-- | coverage/collector.py | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/coverage/collector.py b/coverage/collector.py index 39acd7bd..ded6d920 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 |