diff --git a/AUTHORS.rst b/AUTHORS.rst index 2ad80a00..aa5338a8 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -57,3 +57,4 @@ Authors * Colin O'Dell - https://github.com/colinodell * Ronny Pfannschmidt - https://github.com/RonnyPfannschmidt * Christian Fetzer - https://github.com/fetzerch +* Ofek Lev - https://ofek.dev diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c49683f5..d2250280 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,12 @@ Changelog ========= +4.0.1 (2022-10-26) +------------------ + +* Remove forced config file default of ``.coveragerc`` + Contributed by Ofek Lev in + `#508 `_. 4.0.0 (2022-09-28) ------------------ @@ -33,7 +39,6 @@ Changelog Contributed by Bruno Oliveira in `#549 `_ and Ronny Pfannschmidt in `#550 `_. - 3.0.0 (2021-10-04) ------------------- diff --git a/src/pytest_cov/embed.py b/src/pytest_cov/embed.py index f8a2749f..70bdd8e1 100644 --- a/src/pytest_cov/embed.py +++ b/src/pytest_cov/embed.py @@ -42,7 +42,7 @@ def init(): cov_source = None else: cov_source = cov_source.split(os.pathsep) - if cov_config == os.pathsep: + if cov_config != '': cov_config = True # Activate coverage for this process. diff --git a/src/pytest_cov/engine.py b/src/pytest_cov/engine.py index bfede8c7..b9ea252c 100644 --- a/src/pytest_cov/engine.py +++ b/src/pytest_cov/engine.py @@ -70,6 +70,10 @@ def __init__(self, cov_source, cov_report, cov_config, cov_append, cov_branch, c self.topdir = os.getcwd() self.is_collocated = None + # If unset (the default), indicate fallback behavior for other files like pyproject.toml. + # See https://github.com/nedbat/coveragepy/blob/6.2/coverage/control.py#L144-L146 + self.config_file = self.cov_config or True + @contextlib.contextmanager def ensure_topdir(self): original_cwd = os.getcwd() @@ -98,7 +102,7 @@ def set_env(self): if os.path.exists(config_file): os.environ['COV_CORE_CONFIG'] = config_file else: - os.environ['COV_CORE_CONFIG'] = os.pathsep + os.environ['COV_CORE_CONFIG'] = '' os.environ['COV_CORE_DATAFILE'] = os.path.abspath(self.cov.config.data_file) if self.cov_branch: os.environ['COV_CORE_BRANCH'] = 'enabled' @@ -221,12 +225,12 @@ def start(self): self.cov = coverage.Coverage(source=self.cov_source, branch=self.cov_branch, data_suffix=True, - config_file=self.cov_config) + config_file=self.config_file) self.combining_cov = coverage.Coverage(source=self.cov_source, branch=self.cov_branch, data_suffix=True, data_file=os.path.abspath(self.cov.config.data_file), - config_file=self.cov_config) + config_file=self.config_file) # Erase or load any previous coverage data and start coverage. if not self.cov_append: @@ -265,7 +269,7 @@ def start(self): self.cov = coverage.Coverage(source=self.cov_source, branch=self.cov_branch, data_suffix=True, - config_file=self.cov_config) + config_file=self.config_file) self.cov._warn_no_data = False self.cov._warn_unimported_source = False self.cov._warn_preimported_source = False @@ -273,7 +277,7 @@ def start(self): branch=self.cov_branch, data_suffix=True, data_file=os.path.abspath(self.cov.config.data_file), - config_file=self.cov_config) + config_file=self.config_file) if not self.cov_append: self.cov.erase() self.cov.start() @@ -310,7 +314,7 @@ def testnodedown(self, node, error): cov = coverage.Coverage(source=self.cov_source, branch=self.cov_branch, data_suffix=data_suffix, - config_file=self.cov_config) + config_file=self.config_file) cov.start() if coverage.version_info < (5, 0): data = CoverageData() @@ -368,7 +372,7 @@ def start(self): self.cov = coverage.Coverage(source=self.cov_source, branch=self.cov_branch, data_suffix=True, - config_file=self.cov_config) + config_file=self.config_file) self.cov.start() self.set_env() diff --git a/src/pytest_cov/plugin.py b/src/pytest_cov/plugin.py index dd7b8c4e..b49eb7f4 100644 --- a/src/pytest_cov/plugin.py +++ b/src/pytest_cov/plugin.py @@ -104,9 +104,9 @@ def pytest_addoption(parser): 'annotate, html, xml and lcov may be followed by ":DEST" ' 'where DEST specifies the output location. ' 'Use --cov-report= to not generate any output.') - group.addoption('--cov-config', action='store', default='.coveragerc', + group.addoption('--cov-config', action='store', default='', metavar='PATH', - help='Config file for coverage. Default: .coveragerc') + help='Config file for coverage.') group.addoption('--no-cov-on-fail', action='store_true', default=False, help='Do not report coverage if test run fails. ' 'Default: False')