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
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
1 change: 1 addition & 0 deletions changelog/14442.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a regression where ``--strict-markers`` and ``--strict-config`` specified through ``addopts`` were silently ignored.
4 changes: 3 additions & 1 deletion 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,8 @@ 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)
)
self._inicfg.update(parse_override_ini(self.known_args_namespace.override_ini))
self._inicache.clear()
self._checkversion()
self._consider_importhook()
self._configure_python_path()
Expand All @@ -1541,7 +1544,6 @@ 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)
)

self._validate_plugins()
self._warn_about_skipped_plugins()

Expand Down
14 changes: 14 additions & 0 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,20 @@ def test_strict_config_ini_option(
result.stderr.fnmatch_lines("ERROR: Unknown config option: unknown_option")
assert result.ret == pytest.ExitCode.USAGE_ERROR

def test_strict_config_from_addopts(self, pytester: Pytester) -> None:
pytester.makeini(
"""
[pytest]
addopts = --strict-config
unknown_option = 1
"""
)

result = pytester.runpytest()

result.stderr.fnmatch_lines(["ERROR: Unknown config option: unknown_option"])
assert result.ret == pytest.ExitCode.USAGE_ERROR

@pytest.mark.filterwarnings("default::pytest.PytestConfigWarning")
def test_disable_warnings_plugin_disables_config_warnings(
self, pytester: Pytester
Expand Down
25 changes: 25 additions & 0 deletions testing/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,31 @@ def test_hello():
)


def test_strict_markers_from_addopts(pytester: Pytester) -> None:
pytester.makeini(
"""
[pytest]
addopts = --strict-markers
"""
)
pytester.makepyfile(
"""
import pytest

@pytest.mark.unregisteredmark
def test_hello():
pass
"""
)

result = pytester.runpytest()

result.stdout.fnmatch_lines(
["'unregisteredmark' not found in `markers` configuration option"]
)
assert result.ret == pytest.ExitCode.INTERRUPTED


@pytest.mark.parametrize(
("expr", "expected_passed"),
[
Expand Down
Loading