Skip to content

Commit 0a27f69

Browse files
committed
Fix early_config.known_args_namespace not containing third-party options
Regression introduced in #7700
1 parent a6b5de7 commit 0a27f69

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/_pytest/config/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,10 @@ def _preparse(self, args: List[str], addopts: bool = True) -> None:
11671167
self.pluginmanager.load_setuptools_entrypoints("pytest11")
11681168
self.pluginmanager.consider_env()
11691169

1170+
self.known_args_namespace = self._parser.parse_known_args(
1171+
args, namespace=copy.copy(self.known_args_namespace)
1172+
)
1173+
11701174
self._validate_plugins()
11711175
self._warn_about_skipped_plugins()
11721176

testing/test_config.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,25 @@ def my_dists():
412412
else:
413413
testdir.parseconfig()
414414

415+
def test_early_config_cmdline(self, testdir, monkeypatch):
416+
"""early_config contains options registered by third-party plugins.
417+
418+
This is a regression involving pytest-cov (and possibly others) introduced in #7700.
419+
"""
420+
testdir.makepyfile(
421+
myplugin="""
422+
def pytest_addoption(parser):
423+
parser.addoption('--foo', default=None, dest='foo')
424+
425+
def pytest_load_initial_conftests(early_config, parser, args):
426+
assert early_config.known_args_namespace.foo == "1"
427+
"""
428+
)
429+
monkeypatch.setenv("PYTEST_PLUGINS", "myplugin")
430+
testdir.syspathinsert()
431+
result = testdir.runpytest("--foo=1")
432+
result.stdout.fnmatch_lines("* no tests ran in *")
433+
415434

416435
class TestConfigCmdlineParsing:
417436
def test_parsing_again_fails(self, testdir):

0 commit comments

Comments
 (0)