summaryrefslogtreecommitdiff
path: root/test/coveragetest.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2011-03-24 22:49:37 -0400
committerNed Batchelder <ned@nedbatchelder.com>2011-03-24 22:49:37 -0400
commit01ea68a1088fc1cdbdd586624ac695c5b697edeb (patch)
tree7b64f69deaeda1fa07c38bfdb64c7c4d8e879eb3 /test/coveragetest.py
parent1f950ca6c4c1da6d5f2f37faeb0217e9ff273b75 (diff)
downloadpython-coveragepy-git-01ea68a1088fc1cdbdd586624ac695c5b697edeb.tar.gz
Incremental HTML generation. Some cleanup would be good.
Diffstat (limited to 'test/coveragetest.py')
-rw-r--r--test/coveragetest.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/test/coveragetest.py b/test/coveragetest.py
index 621d7ae2..93cffa86 100644
--- a/test/coveragetest.py
+++ b/test/coveragetest.py
@@ -1,6 +1,6 @@
"""Base test case class for coverage testing."""
-import imp, os, random, shlex, shutil, sys, tempfile, textwrap
+import glob, imp, os, random, shlex, shutil, sys, tempfile, textwrap
import coverage
from coverage.backward import sorted, StringIO # pylint: disable=W0622
@@ -83,6 +83,9 @@ class CoverageTest(TestCase):
sys.stdout = self.old_stdout
sys.stderr = self.old_stderr
+ self.clean_modules()
+
+ def clean_modules(self):
# Remove any new modules imported during the test run. This lets us
# import the same source files for more than one test.
for m in [m for m in sys.modules if m not in self.old_modules]:
@@ -155,6 +158,23 @@ class CoverageTest(TestCase):
return filename
+ def clean_local_file_imports(self):
+ """Clean up the results of calls to `import_local_file`.
+
+ Use this if you need to `import_local_file` the same file twice in
+ one test.
+
+ """
+ # So that we can re-import files, clean them out first.
+ self.clean_modules()
+ # Also have to clean out the .pyc file, since the timestamp
+ # resolution is only one second, a changed file might not be
+ # picked up.
+ for pyc in glob.glob('*.pyc'):
+ os.remove(pyc)
+ if os.path.exists("__pycache__"):
+ shutil.rmtree("__pycache__")
+
def import_local_file(self, modname):
"""Import a local file as a module.