Skip to content
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
10 changes: 9 additions & 1 deletion src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,15 @@ def __init__(self, options: argparse.Namespace, pluginmanager, start=True, no_co
self.options = options
self._wrote_heading = False

is_dist = getattr(options, 'numprocesses', False) or getattr(options, 'distload', False) or getattr(options, 'dist', 'no') != 'no'
# The distribution mode only takes effect when xdist has execution
# environments. ``--dist`` may be configured without ``-n``; in that
# case pytest still runs in the current process and needs the central
# controller to configure subprocess coverage.
is_dist = (
bool(getattr(options, 'numprocesses', False))
or getattr(options, 'distload', False)
or (getattr(options, 'dist', 'no') != 'no' and bool(getattr(options, 'tx', ())))
)
if getattr(options, 'no_cov', False):
self._disabled = True
return
Expand Down
24 changes: 24 additions & 0 deletions tests/test_pytest_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,30 @@ def test_foo():
assert result.ret == 0


def test_dist_option_without_numprocesses_uses_central_controller(monkeypatch):
started = []
monkeypatch.setattr(
pytest_cov.plugin.CovPlugin,
'start',
lambda self, controller_cls, config=None, nodeid=None: started.append(
controller_cls.__name__
),
)
options = SimpleNamespace(
cov_report={},
cov_source=['.'],
dist='loadgroup',
distload=False,
no_cov=False,
numprocesses=None,
tx=[],
)

pytest_cov.plugin.CovPlugin(options, None)

assert started == ['Central']


@pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"')
def test_dist_subprocess_collocated(testdir):
testdir.makepyprojecttoml(
Expand Down