Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ Piotr Banaszkiewicz
Piotr Helm
Poulami Sau
Prakhar Gurunani
Praneeth Kodumagulla
Prashant Anand
Prashant Sharma
Pulkit Goyal
Expand Down
3 changes: 3 additions & 0 deletions changelog/14442.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed a regression in pytest 9.0 where :option:`--strict-markers` and :option:`--strict-config` specified through :confval:`addopts` were silently ignored.

Note that when targeting pytest >= 9.0, it's nicer to use :confval:`strict_markers` and :confval:`strict_config`, or :ref:`strict mode <strict mode>`.
7 changes: 7 additions & 0 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from .findpaths import ConfigDict
from .findpaths import ConfigValue
from .findpaths import determine_setup
from .findpaths import parse_override_ini
from _pytest import __version__
import _pytest._code
from _pytest._code import ExceptionInfo
Expand Down Expand Up @@ -1520,6 +1521,12 @@ def parse(self, args: list[str], addopts: bool = True) -> None:
self.known_args_namespace = self._parser.parse_known_args(
args, namespace=copy.copy(self.option)
)
if addopts:
# addopts may have added overrides (especially via OverrideIniAction).
# The thing can be endlessly circular but we only do one level (#14442).
if overrides := parse_override_ini(self.known_args_namespace.override_ini):
self._inicfg.update(overrides)
self._inicache.clear()
self._checkversion()
self._consider_importhook()
self._configure_python_path()
Expand Down
15 changes: 10 additions & 5 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,16 +475,21 @@ def test_silence_unknown_key_warning(self, pytester: Pytester) -> None:
result = pytester.runpytest()
result.stdout.no_fnmatch_line("*PytestConfigWarning*")

@pytest.mark.parametrize("option_name", ["strict_config", "strict"])
def test_strict_config_ini_option(
self, pytester: Pytester, option_name: str
) -> None:
@pytest.mark.parametrize(
"option",
[
"strict_config = true",
"strict = true",
"addopts = --strict-config",
],
)
def test_strict_config_ini_option(self, pytester: Pytester, option: str) -> None:
"""Test that strict_config and strict ini options enable strict config checking."""
pytester.makeini(
f"""
[pytest]
unknown_option = 1
{option_name} = True
{option}
"""
)
result = pytester.runpytest()
Expand Down
21 changes: 13 additions & 8 deletions testing/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,16 @@ def test_hello():


@pytest.mark.parametrize(
"option_name", ["--strict-markers", "--strict", "strict_markers", "strict"]
"option",
[
"--strict-markers",
"--strict",
"strict_markers = true",
"strict = true",
"addopts = --strict-markers",
],
)
def test_strict_prohibits_unregistered_markers(
pytester: Pytester, option_name: str
) -> None:
def test_strict_prohibits_unregistered_markers(pytester: Pytester, option: str) -> None:
pytester.makepyfile(
"""
import pytest
Expand All @@ -197,16 +202,16 @@ def test_hello():
pass
"""
)
if option_name in ("strict_markers", "strict"):
if option.startswith("-"):
result = pytester.runpytest(option)
else:
pytester.makeini(
f"""
[pytest]
{option_name} = true
{option}
"""
)
result = pytester.runpytest()
else:
result = pytester.runpytest(option_name)
assert result.ret != 0
result.stdout.fnmatch_lines(
["'unregisteredmark' not found in `markers` configuration option"]
Expand Down
Loading