From 7e10f5b8eda9cd7ce72f4fc5c9a4d7ed0bd45be0 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Thu, 2 Dec 2021 23:11:27 -0500 Subject: [PATCH 1/7] Remove forced config file default of .coveragerc --- src/pytest_cov/plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pytest_cov/plugin.py b/src/pytest_cov/plugin.py index 94a1e494..4d6631ec 100644 --- a/src/pytest_cov/plugin.py +++ b/src/pytest_cov/plugin.py @@ -101,9 +101,9 @@ def pytest_addoption(parser): 'annotate, html and xml 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') From 4ae1e617cc8c8172b20c20d3d6c6f80103671c87 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Mon, 6 Dec 2021 10:16:11 -0500 Subject: [PATCH 2/7] trigger ci --- src/pytest_cov/compat.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pytest_cov/compat.py b/src/pytest_cov/compat.py index f422f25c..8cacf5d2 100644 --- a/src/pytest_cov/compat.py +++ b/src/pytest_cov/compat.py @@ -14,6 +14,7 @@ hookwrapper = pytest.mark.hookwrapper + class SessionWrapper: def __init__(self, session): self._session = session From 2bde461f5fe0ce0a6abda52fba4c467fceea8044 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Mon, 6 Dec 2021 12:27:49 -0500 Subject: [PATCH 3/7] try revert --- src/pytest_cov/plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pytest_cov/plugin.py b/src/pytest_cov/plugin.py index 4d6631ec..94a1e494 100644 --- a/src/pytest_cov/plugin.py +++ b/src/pytest_cov/plugin.py @@ -101,9 +101,9 @@ def pytest_addoption(parser): 'annotate, html and xml 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='', + group.addoption('--cov-config', action='store', default='.coveragerc', metavar='PATH', - help='Config file for coverage.') + help='Config file for coverage. Default: .coveragerc') group.addoption('--no-cov-on-fail', action='store_true', default=False, help='Do not report coverage if test run fails. ' 'Default: False') From 9d6fcbec376dc66401115400ca5b61348ccf2838 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Sun, 12 Dec 2021 16:55:00 -0500 Subject: [PATCH 4/7] fix more tests --- src/pytest_cov/compat.py | 1 - src/pytest_cov/engine.py | 18 +++++++++++------- src/pytest_cov/plugin.py | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/pytest_cov/compat.py b/src/pytest_cov/compat.py index 8cacf5d2..f422f25c 100644 --- a/src/pytest_cov/compat.py +++ b/src/pytest_cov/compat.py @@ -14,7 +14,6 @@ hookwrapper = pytest.mark.hookwrapper - class SessionWrapper: def __init__(self, session): self._session = session diff --git a/src/pytest_cov/engine.py b/src/pytest_cov/engine.py index 0303c2f1..9c0a8364 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_choice = 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' @@ -209,12 +213,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_choice) 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_choice) # Erase or load any previous coverage data and start coverage. if not self.cov_append: @@ -253,7 +257,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_choice) self.cov._warn_no_data = False self.cov._warn_unimported_source = False self.cov._warn_preimported_source = False @@ -261,7 +265,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_choice) if not self.cov_append: self.cov.erase() self.cov.start() @@ -298,7 +302,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_choice) cov.start() if coverage.version_info < (5, 0): data = CoverageData() @@ -356,7 +360,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_choice) self.cov.start() self.set_env() diff --git a/src/pytest_cov/plugin.py b/src/pytest_cov/plugin.py index 94a1e494..4d6631ec 100644 --- a/src/pytest_cov/plugin.py +++ b/src/pytest_cov/plugin.py @@ -101,9 +101,9 @@ def pytest_addoption(parser): 'annotate, html and xml 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') From 5c8763443a73f0c6d8f467eda25dd717b9426b05 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Tue, 21 Dec 2021 12:29:11 -0500 Subject: [PATCH 5/7] update AUTHORS & CHANGELOG --- AUTHORS.rst | 1 + CHANGELOG.rst | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 489903c2..997dcc96 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -51,3 +51,4 @@ Authors * Danilo Šegan - https://github.com/dsegan * Michał Bielawski - https://github.com/D3X * Zac Hatfield-Dodds - https://github.com/Zac-HD +* Ofek Lev - https://ofek.dev diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3087426b..46a818a5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,9 +5,12 @@ Changelog 3.1.0 (future) ------------------- -* `--cov-fail-under` no longer causes `pytest --collect-only` to fail +* ``--cov-fail-under`` no longer causes ``pytest --collect-only`` to fail Contributed by Zac Hatfield-Dodds in `#511 `_. +* Remove forced config file default of ``.coveragerc`` + Contributed by Ofek Lev in + `#508 `_. 3.0.0 (2021-10-04) From edfd68ea9269664c822dd1b1d133f8e192e323f4 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 26 Oct 2022 19:42:49 +0100 Subject: [PATCH 6/7] Update CHANGELOG.rst --- CHANGELOG.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 45cd3ef3..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) ------------------ @@ -32,9 +38,6 @@ Changelog * Modernized pytest hook implementation. Contributed by Bruno Oliveira in `#549 `_ and Ronny Pfannschmidt in `#550 `_. -* Remove forced config file default of ``.coveragerc`` - Contributed by Ofek Lev in - `#508 `_. 3.0.0 (2021-10-04) ------------------- From 8b03e4534f1c931dcb329c43193696ba4a749c06 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Sat, 29 Oct 2022 17:44:21 -0400 Subject: [PATCH 7/7] fix --- src/pytest_cov/embed.py | 2 +- src/pytest_cov/engine.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) 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 887c1675..b9ea252c 100644 --- a/src/pytest_cov/engine.py +++ b/src/pytest_cov/engine.py @@ -72,7 +72,7 @@ def __init__(self, cov_source, cov_report, cov_config, cov_append, cov_branch, c # 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_choice = self.cov_config or True + self.config_file = self.cov_config or True @contextlib.contextmanager def ensure_topdir(self): @@ -225,12 +225,12 @@ def start(self): self.cov = coverage.Coverage(source=self.cov_source, branch=self.cov_branch, data_suffix=True, - config_file=self.config_file_choice) + 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.config_file_choice) + config_file=self.config_file) # Erase or load any previous coverage data and start coverage. if not self.cov_append: @@ -269,7 +269,7 @@ def start(self): self.cov = coverage.Coverage(source=self.cov_source, branch=self.cov_branch, data_suffix=True, - config_file=self.config_file_choice) + config_file=self.config_file) self.cov._warn_no_data = False self.cov._warn_unimported_source = False self.cov._warn_preimported_source = False @@ -277,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.config_file_choice) + config_file=self.config_file) if not self.cov_append: self.cov.erase() self.cov.start() @@ -314,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.config_file_choice) + config_file=self.config_file) cov.start() if coverage.version_info < (5, 0): data = CoverageData() @@ -372,7 +372,7 @@ def start(self): self.cov = coverage.Coverage(source=self.cov_source, branch=self.cov_branch, data_suffix=True, - config_file=self.config_file_choice) + config_file=self.config_file) self.cov.start() self.set_env()