diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2016-11-09 12:47:07 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2016-11-09 12:47:07 -0500 |
commit | 009809830a1afd07ef8d424fc72bfe314e62658d (patch) | |
tree | c798aa2e35c06b8e41d914f7e53ebee050d103b5 | |
parent | 7cf68f3c7ddaec63dac671a2e57ddb6f668cb067 (diff) | |
download | python-coveragepy-git-009809830a1afd07ef8d424fc72bfe314e62658d.tar.gz |
When importing newly made files, we have to invalidate import caches
-rw-r--r-- | coverage/backward.py | 6 | ||||
-rw-r--r-- | tests/coveragetest.py | 3 |
2 files changed, 9 insertions, 0 deletions
diff --git a/coverage/backward.py b/coverage/backward.py index c7b607a9..8d2218d2 100644 --- a/coverage/backward.py +++ b/coverage/backward.py @@ -144,6 +144,12 @@ except AttributeError: PYC_MAGIC_NUMBER = imp.get_magic() +def invalidate_import_caches(): + """Invalidate any import caches that may or may not exist.""" + if importlib and hasattr(importlib, "invalidate_caches"): + importlib.invalidate_caches() + + def import_local_file(modname, modfile=None): """Import a local file as a module. diff --git a/tests/coveragetest.py b/tests/coveragetest.py index 9410e071..dacb9b63 100644 --- a/tests/coveragetest.py +++ b/tests/coveragetest.py @@ -21,6 +21,7 @@ from unittest_mixins import ( import coverage from coverage.backunittest import TestCase from coverage.backward import StringIO, import_local_file, string_class, shlex_quote +from coverage.backward import invalidate_import_caches from coverage.cmdline import CoverageScript from coverage.debug import _TEST_NAME_FILE, DebugControl @@ -77,6 +78,8 @@ class CoverageTest( if os.path.exists("__pycache__"): shutil.rmtree("__pycache__") + invalidate_import_caches() + def import_local_file(self, modname, modfile=None): """Import a local file as a module. |