diff --git a/changelog/7530.deprecation.rst b/changelog/7530.deprecation.rst new file mode 100644 index 0000000000..36a763e51f --- /dev/null +++ b/changelog/7530.deprecation.rst @@ -0,0 +1,4 @@ +The ``--strict`` command-line option has been deprecated, use ``--strict-markers`` instead. + +We have plans to maybe in the future to reintroduce ``--strict`` and make it an encompassing flag for all strictness +related options (``--strict-markers`` and ``--strict-config`` at the moment, more might be introduced in the future). diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index 14d1eeb98a..d588b1bea8 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -18,6 +18,19 @@ Deprecated Features Below is a complete list of all pytest features which are considered deprecated. Using those features will issue :class:`PytestWarning` or subclasses, which can be filtered using :ref:`standard warning filters `. +The ``--strict`` command-line option +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. deprecated:: 6.2 + +The ``--strict`` command-line option has been deprecated in favor of ``--strict-markers``, which +better conveys what the option does. + +We have plans to maybe in the future to reintroduce ``--strict`` and make it an encompassing +flag for all strictness related options (``--strict-markers`` and ``--strict-config`` +at the moment, more might be introduced in the future). + + The ``pytest_warning_captured`` hook ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 7e486e99e5..35d7dbe504 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -40,6 +40,7 @@ import _pytest._code import _pytest.deprecated import _pytest.hookspec +from .. import deprecated from .exceptions import PrintHelp as PrintHelp from .exceptions import UsageError as UsageError from .findpaths import determine_setup @@ -1177,6 +1178,9 @@ def _preparse(self, args: List[str], addopts: bool = True) -> None: self._validate_plugins() self._warn_about_skipped_plugins() + if self.known_args_namespace.strict: + self.issue_config_time_warning(deprecated.STRICT_OPTION, stacklevel=2) + if self.known_args_namespace.confcutdir is None and self.inipath is not None: confcutdir = str(self.inipath.parent) self.known_args_namespace.confcutdir = confcutdir diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index fd00fe2d6d..a9a162f41f 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -51,3 +51,7 @@ "The gethookproxy() and isinitpath() methods of FSCollector and Package are deprecated; " "use self.session.gethookproxy() and self.session.isinitpath() instead. " ) + +STRICT_OPTION = PytestDeprecationWarning( + "The --strict option is deprecated, use --strict-markers instead." +) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index d8a208a1a2..04b51ac00f 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -101,10 +101,12 @@ def pytest_addoption(parser: Parser) -> None: ) group._addoption( "--strict-markers", - "--strict", action="store_true", help="markers not registered in the `markers` section of the configuration file raise errors.", ) + group._addoption( + "--strict", action="store_true", help="(deprecated) alias to --strict-markers.", + ) group._addoption( "-c", metavar="file", diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index 6cbdf8b306..6c126cf4a2 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -496,7 +496,7 @@ def __getattr__(self, name: str) -> MarkDecorator: # If the name is not in the set of known marks after updating, # then it really is time to issue a warning or an error. if name not in self._markers: - if self._config.option.strict_markers: + if self._config.option.strict_markers or self._config.option.strict: fail( f"{name!r} not found in `markers` configuration option", pytrace=False, diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index 5fe9ad7305..1d5feabb7d 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -4,6 +4,7 @@ import pytest from _pytest import deprecated +from _pytest.pytester import Pytester from _pytest.pytester import Testdir @@ -95,3 +96,22 @@ def test_foo(): pass session.gethookproxy(testdir.tmpdir) session.isinitpath(testdir.tmpdir) assert len(rec) == 0 + + +def test_strict_option_is_deprecated(pytester: Pytester) -> None: + """--strict is a deprecated alias to --strict-markers (#7530).""" + pytester.makepyfile( + """ + import pytest + + @pytest.mark.unknown + def test_foo(): pass + """ + ) + result = pytester.runpytest("--strict") + result.stdout.fnmatch_lines( + [ + "'unknown' not found in `markers` configuration option", + "*PytestDeprecationWarning: the --strict option is deprecated, use --strict-markers instead.", + ] + )