Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

4.0.1 (2022-10-26)
------------------

* Remove forced config file default of ``.coveragerc``
Contributed by Ofek Lev in
`#508 <https://github.com/pytest-dev/pytest-cov/pull/508>`_.

4.0.0 (2022-09-28)
------------------
Expand Down Expand Up @@ -33,7 +39,6 @@ Changelog
Contributed by Bruno Oliveira in `#549 <https://github.com/pytest-dev/pytest-cov/pull/549>`_
and Ronny Pfannschmidt in `#550 <https://github.com/pytest-dev/pytest-cov/pull/550>`_.


3.0.0 (2021-10-04)
-------------------

Expand Down
18 changes: 11 additions & 7 deletions src/pytest_cov/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I'd simply rename this to config_file. Maybe it's just me but a dropdrown widget pops up in my head when I see "choice" - too much Django I guess xD


@contextlib.contextmanager
def ensure_topdir(self):
original_cwd = os.getcwd()
Expand Down Expand Up @@ -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'] = ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this change is the cause of all the regressions.

Note that we have this in embed.py and you need to keep it working:

        if cov_config == os.pathsep:
            cov_config = True

os.environ['COV_CORE_DATAFILE'] = os.path.abspath(self.cov.config.data_file)
if self.cov_branch:
os.environ['COV_CORE_BRANCH'] = 'enabled'
Expand Down Expand Up @@ -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_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:
Expand Down Expand Up @@ -265,15 +269,15 @@ 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
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)
if not self.cov_append:
self.cov.erase()
self.cov.start()
Expand Down Expand Up @@ -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_choice)
cov.start()
if coverage.version_info < (5, 0):
data = CoverageData()
Expand Down Expand Up @@ -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_choice)
self.cov.start()
self.set_env()

Expand Down
4 changes: 2 additions & 2 deletions src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down