Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove forced config file default of .coveragerc #508

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/pytest_cov/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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 = self.cov_config or True

@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)
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:
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)
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)
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)
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)
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