diff options
author | Felix Horvat <felix.horvat@ocell.io> | 2022-11-17 12:34:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-17 03:34:22 -0800 |
commit | 26445508a2eb1c7ef459a33ec058eb3f3c5b41dd (patch) | |
tree | de2e539150ae838b813a889583e510642989c7b4 /coverage | |
parent | e76b5c7e0117f885f89190de9e07c1d2410ba58b (diff) | |
download | python-coveragepy-git-26445508a2eb1c7ef459a33ec058eb3f3c5b41dd.tar.gz |
feat: added support for finding unexecuted namespace packages (#1387)
* add support for namespace packages
* fixed typo
* update documentation
* fixed lint issues
* changed versionadded
* convert to config setting
* removed pure formatting changes
* code review changes
Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/config.py | 2 | ||||
-rw-r--r-- | coverage/control.py | 1 | ||||
-rw-r--r-- | coverage/files.py | 5 | ||||
-rw-r--r-- | coverage/inorout.py | 8 |
4 files changed, 12 insertions, 4 deletions
diff --git a/coverage/config.py b/coverage/config.py index 7b765edf..994154f6 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -200,6 +200,7 @@ class CoverageConfig: self.fail_under = 0.0 self.format = None self.ignore_errors = False + self.include_namespace_packages = False self.report_include = None self.report_omit = None self.partial_always_list = DEFAULT_PARTIAL_ALWAYS[:] @@ -375,6 +376,7 @@ class CoverageConfig: ('fail_under', 'report:fail_under', 'float'), ('format', 'report:format', 'boolean'), ('ignore_errors', 'report:ignore_errors', 'boolean'), + ('include_namespace_packages', 'report:include_namespace_packages', 'boolean'), ('partial_always_list', 'report:partial_branches_always', 'regexlist'), ('partial_list', 'report:partial_branches', 'regexlist'), ('precision', 'report:precision', 'int'), diff --git a/coverage/control.py b/coverage/control.py index 91ad5a78..a955c283 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -530,6 +530,7 @@ class Coverage: self._inorout = InOrOut( warn=self._warn, debug=(self._debug if self._debug.should('trace') else None), + include_namespace_packages=self.config.include_namespace_packages ) self._inorout.configure(self.config) self._inorout.plugins = self._plugins diff --git a/coverage/files.py b/coverage/files.py index bfd808ff..8be292f3 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -461,7 +461,7 @@ class PathAliases: return path -def find_python_files(dirname): +def find_python_files(dirname, include_namespace_packages): """Yield all of the importable Python files in `dirname`, recursively. To be importable, the files have to be in a directory with a __init__.py, @@ -472,7 +472,8 @@ def find_python_files(dirname): """ for i, (dirpath, dirnames, filenames) in enumerate(os.walk(dirname)): - if i > 0 and '__init__.py' not in filenames: + if (i > 0 and '__init__.py' not in filenames + and not include_namespace_packages): # If a directory doesn't have __init__.py, then it isn't # importable and neither are its files del dirnames[:] diff --git a/coverage/inorout.py b/coverage/inorout.py index 2e534c85..0d3f6d67 100644 --- a/coverage/inorout.py +++ b/coverage/inorout.py @@ -189,9 +189,10 @@ def add_coverage_paths(paths): class InOrOut: """Machinery for determining what files to measure.""" - def __init__(self, warn, debug): + def __init__(self, warn, debug, include_namespace_packages): self.warn = warn self.debug = debug + self.include_namespace_packages = include_namespace_packages # The matchers for should_trace. self.source_match = None @@ -565,7 +566,10 @@ class InOrOut: Yield the file path, and the plugin name that handles the file. """ - py_files = ((py_file, None) for py_file in find_python_files(src_dir)) + py_files = ( + (py_file, None) for py_file in + find_python_files(src_dir, self.include_namespace_packages) + ) plugin_files = self._find_plugin_files(src_dir) for file_path, plugin_name in itertools.chain(py_files, plugin_files): |