summaryrefslogtreecommitdiff
path: root/coverage/inorout.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-10-11 15:22:18 -0400
committerNed Batchelder <ned@nedbatchelder.com>2021-10-11 16:15:40 -0400
commit260359756694728cd13f8c8715dddf7c6e2f371d (patch)
tree4ed1f110286dd34c53b9d1169d1d94c83bc89ac3 /coverage/inorout.py
parentfdaa8224ccfa16233fda0c84860ef95ca073ee95 (diff)
downloadpython-coveragepy-git-260359756694728cd13f8c8715dddf7c6e2f371d.tar.gz
fix: source modules need to be re-imported. #1232
Diffstat (limited to 'coverage/inorout.py')
-rw-r--r--coverage/inorout.py38
1 files changed, 20 insertions, 18 deletions
diff --git a/coverage/inorout.py b/coverage/inorout.py
index c90e3d59..2c216ea9 100644
--- a/coverage/inorout.py
+++ b/coverage/inorout.py
@@ -18,6 +18,7 @@ from coverage.disposition import FileDisposition, disposition_init
from coverage.exceptions import CoverageException
from coverage.files import TreeMatcher, FnmatchMatcher, ModuleMatcher
from coverage.files import prep_patterns, find_python_files, canonical_filename
+from coverage.misc import sys_modules_saved
from coverage.python import source_for_file, source_for_morf
@@ -270,27 +271,28 @@ class InOrOut:
# Check if the source we want to measure has been installed as a
# third-party package.
- for pkg in self.source_pkgs:
- try:
- modfile, path = file_and_path_for_module(pkg)
- debug(f"Imported source package {pkg!r} as {modfile!r}")
- except CoverageException as exc:
- debug(f"Couldn't import source package {pkg!r}: {exc}")
- continue
- if modfile:
- if self.third_match.match(modfile):
- debug(
- f"Source is in third-party because of source_pkg {pkg!r} at {modfile!r}"
- )
- self.source_in_third = True
- else:
- for pathdir in path:
- if self.third_match.match(pathdir):
+ with sys_modules_saved():
+ for pkg in self.source_pkgs:
+ try:
+ modfile, path = file_and_path_for_module(pkg)
+ debug(f"Imported source package {pkg!r} as {modfile!r}")
+ except CoverageException as exc:
+ debug(f"Couldn't import source package {pkg!r}: {exc}")
+ continue
+ if modfile:
+ if self.third_match.match(modfile):
debug(
- f"Source is in third-party because of {pkg!r} path directory " +
- f"at {pathdir!r}"
+ f"Source is in third-party because of source_pkg {pkg!r} at {modfile!r}"
)
self.source_in_third = True
+ else:
+ for pathdir in path:
+ if self.third_match.match(pathdir):
+ debug(
+ f"Source is in third-party because of {pkg!r} path directory " +
+ f"at {pathdir!r}"
+ )
+ self.source_in_third = True
for src in self.source:
if self.third_match.match(src):