Skip to content

Commit

Permalink
Deprecate --strict
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Nov 6, 2020
1 parent 1c18fb8 commit 441eaba
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
4 changes: 4 additions & 0 deletions 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).
13 changes: 13 additions & 0 deletions doc/en/deprecations.rst
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
5 changes: 5 additions & 0 deletions src/_pytest/config/__init__.py
Expand Up @@ -1177,6 +1177,11 @@ 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(
_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
Expand Down
4 changes: 4 additions & 0 deletions src/_pytest/deprecated.py
Expand Up @@ -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."
)
4 changes: 3 additions & 1 deletion src/_pytest/main.py
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/mark/structures.py
Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions testing/deprecated_test.py
Expand Up @@ -4,6 +4,7 @@

import pytest
from _pytest import deprecated
from _pytest.pytester import Pytester
from _pytest.pytester import Testdir


Expand Down Expand Up @@ -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.",
]
)

0 comments on commit 441eaba

Please sign in to comment.