summaryrefslogtreecommitdiff
path: root/test/coveragetest.py
diff options
context:
space:
mode:
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.