Skip to content

Commit 30287b4

Browse files
authored
Deprecate --strict (#7985)
Fix #7530
1 parent 4cd0fde commit 30287b4

File tree

7 files changed

+50
-2
lines changed

7 files changed

+50
-2
lines changed

changelog/7530.deprecation.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The ``--strict`` command-line option has been deprecated, use ``--strict-markers`` instead.
2+
3+
We have plans to maybe in the future to reintroduce ``--strict`` and make it an encompassing flag for all strictness
4+
related options (``--strict-markers`` and ``--strict-config`` at the moment, more might be introduced in the future).

doc/en/deprecations.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ Deprecated Features
1818
Below is a complete list of all pytest features which are considered deprecated. Using those features will issue
1919
:class:`PytestWarning` or subclasses, which can be filtered using :ref:`standard warning filters <warnings>`.
2020

21+
The ``--strict`` command-line option
22+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23+
24+
.. deprecated:: 6.2
25+
26+
The ``--strict`` command-line option has been deprecated in favor of ``--strict-markers``, which
27+
better conveys what the option does.
28+
29+
We have plans to maybe in the future to reintroduce ``--strict`` and make it an encompassing
30+
flag for all strictness related options (``--strict-markers`` and ``--strict-config``
31+
at the moment, more might be introduced in the future).
32+
33+
2134

2235
The ``pytest_warning_captured`` hook
2336
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/_pytest/config/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,11 @@ def _preparse(self, args: List[str], addopts: bool = True) -> None:
11771177
self._validate_plugins()
11781178
self._warn_about_skipped_plugins()
11791179

1180+
if self.known_args_namespace.strict:
1181+
self.issue_config_time_warning(
1182+
_pytest.deprecated.STRICT_OPTION, stacklevel=2
1183+
)
1184+
11801185
if self.known_args_namespace.confcutdir is None and self.inipath is not None:
11811186
confcutdir = str(self.inipath.parent)
11821187
self.known_args_namespace.confcutdir = confcutdir

src/_pytest/deprecated.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@
5151
"The gethookproxy() and isinitpath() methods of FSCollector and Package are deprecated; "
5252
"use self.session.gethookproxy() and self.session.isinitpath() instead. "
5353
)
54+
55+
STRICT_OPTION = PytestDeprecationWarning(
56+
"The --strict option is deprecated, use --strict-markers instead."
57+
)

src/_pytest/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ def pytest_addoption(parser: Parser) -> None:
101101
)
102102
group._addoption(
103103
"--strict-markers",
104-
"--strict",
105104
action="store_true",
106105
help="markers not registered in the `markers` section of the configuration file raise errors.",
107106
)
107+
group._addoption(
108+
"--strict", action="store_true", help="(deprecated) alias to --strict-markers.",
109+
)
108110
group._addoption(
109111
"-c",
110112
metavar="file",

src/_pytest/mark/structures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ def __getattr__(self, name: str) -> MarkDecorator:
496496
# If the name is not in the set of known marks after updating,
497497
# then it really is time to issue a warning or an error.
498498
if name not in self._markers:
499-
if self._config.option.strict_markers:
499+
if self._config.option.strict_markers or self._config.option.strict:
500500
fail(
501501
f"{name!r} not found in `markers` configuration option",
502502
pytrace=False,

testing/deprecated_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66
from _pytest import deprecated
7+
from _pytest.pytester import Pytester
78
from _pytest.pytester import Testdir
89

910

@@ -95,3 +96,22 @@ def test_foo(): pass
9596
session.gethookproxy(testdir.tmpdir)
9697
session.isinitpath(testdir.tmpdir)
9798
assert len(rec) == 0
99+
100+
101+
def test_strict_option_is_deprecated(pytester: Pytester) -> None:
102+
"""--strict is a deprecated alias to --strict-markers (#7530)."""
103+
pytester.makepyfile(
104+
"""
105+
import pytest
106+
107+
@pytest.mark.unknown
108+
def test_foo(): pass
109+
"""
110+
)
111+
result = pytester.runpytest("--strict")
112+
result.stdout.fnmatch_lines(
113+
[
114+
"'unknown' not found in `markers` configuration option",
115+
"*PytestDeprecationWarning: The --strict option is deprecated, use --strict-markers instead.",
116+
]
117+
)

0 commit comments

Comments
 (0)