From 07b188473f945262949a5ce0cf3ee7b1e943a6ee Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 7 Jul 2012 09:53:36 -0400 Subject: If the C tracer is missing during testing, make the problem immediately apparent. --- coverage/collector.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'coverage') diff --git a/coverage/collector.py b/coverage/collector.py index 3fdedaad..73a14b93 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -1,12 +1,23 @@ """Raw data collector for Coverage.""" -import sys, threading +import os, sys, threading try: # Use the C extension code when we can, for speed. from coverage.tracer import CTracer 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. + sys.stderr.write( + "*** COVERAGE_TEST_TRACER is 'c' but can't import CTracer!\n" + ) + sys.exit(1) CTracer = None -- cgit v1.2.1