diff options
author | Marc Abramowitz <marc@marc-abramowitz.com> | 2012-07-07 09:27:36 -0700 |
---|---|---|
committer | Marc Abramowitz <marc@marc-abramowitz.com> | 2012-07-07 09:27:36 -0700 |
commit | afb29fd79ca4275bbd427ba5c1a0633dec0ae21d (patch) | |
tree | 702a9142ced05c39a6bcaf2ef219a573a79311df /coverage | |
parent | 4c2f4e949ed4e3cb559fad2d635d2e191dc2f2b2 (diff) | |
parent | 07b188473f945262949a5ce0cf3ee7b1e943a6ee (diff) | |
download | python-coveragepy-git-afb29fd79ca4275bbd427ba5c1a0633dec0ae21d.tar.gz |
Merge with upstream changes
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/collector.py | 13 | ||||
-rw-r--r-- | coverage/files.py | 14 |
2 files changed, 23 insertions, 4 deletions
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 diff --git a/coverage/files.py b/coverage/files.py index e6dc4aa1..e07c5766 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -207,9 +207,17 @@ class PathAliases(object): def find_python_files(dirname): - """Yield all of the importable Python files in `dirname`, recursively.""" - for dirpath, dirnames, filenames in os.walk(dirname, topdown=True): - if '__init__.py' not in filenames: + """Yield all of the importable Python files in `dirname`, recursively. + + To be importable, the files have to be in a directory with a __init__.py, + except for `dirname` itself, which isn't required to have one. The + assumption is that `dirname` was specified directly, so the user knows + best, but subdirectories are checked for a __init__.py to be sure we only + find the importable files. + + """ + for i, (dirpath, dirnames, filenames) in enumerate(os.walk(dirname)): + if i > 0 and '__init__.py' not in filenames: # If a directory doesn't have __init__.py, then it isn't # importable and neither are its files del dirnames[:] |