summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-03-06 08:41:32 -0500
committerNed Batchelder <ned@nedbatchelder.com>2018-03-06 08:41:32 -0500
commit7183742f23535207bfdd1efeec89f1193c9c319a (patch)
treee53a819feb11c404e6ec9f46a958f08a6a04478b /coverage
parentf67950b19465d9ce45d16edcd2360073b2c95b5d (diff)
downloadpython-coveragepy-7183742f23535207bfdd1efeec89f1193c9c319a.tar.gz
check_preimported=True controls whether coverage checks pre-imported files when starting
Diffstat (limited to 'coverage')
-rw-r--r--coverage/cmdline.py1
-rw-r--r--coverage/control.py19
-rw-r--r--coverage/inorout.py3
3 files changed, 13 insertions, 10 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 7b86054..04cf8e8 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -475,6 +475,7 @@ class CoverageScript(object):
include=include,
debug=debug,
concurrency=options.concurrency,
+ check_preimported=True,
)
if options.action == "debug":
diff --git a/coverage/control.py b/coverage/control.py
index 77efe28..55c031a 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -53,15 +53,12 @@ class Coverage(object):
cov.html_report(directory='covhtml')
"""
- # A global to know if we have ever checked for files imported before
- # coverage has been started.
- _checked_preimported = False
def __init__(
self, data_file=None, data_suffix=None, cover_pylib=None,
auto_data=False, timid=None, branch=None, config_file=True,
source=None, omit=None, include=None, debug=None,
- concurrency=None,
+ concurrency=None, check_preimported=False,
):
"""
`data_file` is the base name of the data file to use, defaulting to
@@ -115,12 +112,20 @@ class Coverage(object):
"eventlet", "gevent", "multiprocessing", or "thread" (the default).
This can also be a list of these strings.
+ If `check_preimported` is true, then when coverage is started, the
+ aleady-imported files will be checked to see if they should be measured
+ by coverage. Importing measured files before coverage is started can
+ mean that code is missed.
+
.. versionadded:: 4.0
The `concurrency` parameter.
.. versionadded:: 4.2
The `concurrency` parameter can now be a list of strings.
+ .. versionadded:: 4.6
+ The `check_preimported` parameter.
+
"""
# Build our configuration from a number of sources.
self.config_file, self.config = read_coverage_config(
@@ -141,7 +146,7 @@ class Coverage(object):
# Is it ok for no data to be collected?
self._warn_no_data = True
self._warn_unimported_source = True
- self._warn_preimported_source = True
+ self._warn_preimported_source = check_preimported
# A record of all the warnings that have been issued.
self._warnings = []
@@ -414,8 +419,8 @@ class Coverage(object):
self.load()
# See if we think some code that would eventually be measured has already been imported.
- if not Coverage._checked_preimported and self._warn_preimported_source:
- Coverage._checked_preimported = self._inorout.warn_already_imported_files()
+ if self._warn_preimported_source:
+ self._inorout.warn_already_imported_files()
self.collector.start()
self._started = True
diff --git a/coverage/inorout.py b/coverage/inorout.py
index 640b4e6..53ed8ea 100644
--- a/coverage/inorout.py
+++ b/coverage/inorout.py
@@ -354,9 +354,6 @@ class InOrOut(object):
self.warn(msg, slug="already-imported")
warned.add(filename)
- return True
- return False
-
def warn_unimported_source(self):
for pkg in self.source_pkgs_unmatched:
self.warn_about_unmeasured_code(pkg)