Deprecate --strict (#7985)

Fix #7530
This commit is contained in:
Bruno Oliveira 2020-11-06 05:48:20 -03:00 committed by GitHub
parent 4cd0fde277
commit 30287b49cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 2 deletions

View File

@ -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).

View File

@ -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 <warnings>`.
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -1177,6 +1177,11 @@ class Config:
self._validate_plugins()
self._warn_about_skipped_plugins()
if self.known_args_namespace.strict:
self.issue_config_time_warning(
_pytest.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

View File

@ -51,3 +51,7 @@ FSCOLLECTOR_GETHOOKPROXY_ISINITPATH = PytestDeprecationWarning(
"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."
)

View File

@ -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",

View File

@ -496,7 +496,7 @@ class MarkGenerator:
# 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,

View File

@ -4,6 +4,7 @@ from unittest import mock
import pytest
from _pytest import deprecated
from _pytest.pytester import Pytester
from _pytest.pytester import Testdir
@ -95,3 +96,22 @@ def test_fscollector_gethookproxy_isinitpath(testdir: Testdir) -> None:
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.",
]
)