diff options
author | Ran Benita <ran@unusedvar.com> | 2020-05-11 20:57:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-11 20:57:35 +0300 |
commit | 15d5e8cd97c621cf558d154a5760519468770199 (patch) | |
tree | c98ea3e265a05e2f9fb699c816ef0859df05fc2c | |
parent | 0ba6e1f74ea38401b8dd6387b5c0d2af4ee664c4 (diff) | |
parent | c4f9eaa5de7db6dc23e4f8296f3504a8d684fca0 (diff) | |
download | pytest-15d5e8cd97c621cf558d154a5760519468770199.tar.gz |
Merge pull request #7210 from bluetech/minus-k-deprecations
mark: deprecate a couple undocumented -k syntaxes
-rw-r--r-- | changelog/7210.deprecation.rst | 5 | ||||
-rw-r--r-- | src/_pytest/deprecated.py | 10 | ||||
-rw-r--r-- | src/_pytest/mark/__init__.py | 7 | ||||
-rw-r--r-- | testing/deprecated_test.py | 24 |
4 files changed, 46 insertions, 0 deletions
diff --git a/changelog/7210.deprecation.rst b/changelog/7210.deprecation.rst new file mode 100644 index 000000000..3e1350eaa --- /dev/null +++ b/changelog/7210.deprecation.rst @@ -0,0 +1,5 @@ +The special ``-k '-expr'`` syntax to ``-k`` is deprecated. Use ``-k 'not expr'`` +instead. + +The special ``-k 'expr:'`` syntax to ``-k`` is deprecated. Please open an issue +if you use this and want a replacement. diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index 8c9bd9d5c..9f4570f85 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -75,3 +75,13 @@ TERMINALWRITER_WRITER = PytestDeprecationWarning( "The TerminalReporter.writer attribute is deprecated, use TerminalReporter._tw instead at your own risk.\n" "See https://docs.pytest.org/en/latest/deprecations.html#terminalreporter-writer for more information." ) + + +MINUS_K_DASH = PytestDeprecationWarning( + "The `-k '-expr'` syntax to -k is deprecated.\nUse `-k 'not expr'` instead." +) + +MINUS_K_COLON = PytestDeprecationWarning( + "The `-k 'expr:'` syntax to -k is deprecated.\n" + "Please open an issue if you use this and want a replacement." +) diff --git a/src/_pytest/mark/__init__.py b/src/_pytest/mark/__init__.py index 36245c25a..f7556b0b7 100644 --- a/src/_pytest/mark/__init__.py +++ b/src/_pytest/mark/__init__.py @@ -1,4 +1,5 @@ """ generic mechanism for marking and selecting python functions. """ +import warnings from typing import Optional from .legacy import matchkeyword @@ -13,6 +14,8 @@ from .structures import ParameterSet from _pytest.config import Config from _pytest.config import hookimpl from _pytest.config import UsageError +from _pytest.deprecated import MINUS_K_COLON +from _pytest.deprecated import MINUS_K_DASH from _pytest.store import StoreKey __all__ = ["Mark", "MarkDecorator", "MarkGenerator", "get_empty_parameterset_mark"] @@ -107,9 +110,13 @@ def deselect_by_keyword(items, config): return if keywordexpr.startswith("-"): + # To be removed in pytest 7.0.0. + warnings.warn(MINUS_K_DASH, stacklevel=2) keywordexpr = "not " + keywordexpr[1:] selectuntil = False if keywordexpr[-1:] == ":": + # To be removed in pytest 7.0.0. + warnings.warn(MINUS_K_COLON, stacklevel=2) selectuntil = True keywordexpr = keywordexpr[:-1] diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index 5ad055bd2..edd5505c0 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -164,3 +164,27 @@ def test__fillfuncargs_is_deprecated() -> None: match="The `_fillfuncargs` function is deprecated", ): pytest._fillfuncargs(mock.Mock()) + + +def test_minus_k_dash_is_deprecated(testdir) -> None: + threepass = testdir.makepyfile( + test_threepass=""" + def test_one(): assert 1 + def test_two(): assert 1 + def test_three(): assert 1 + """ + ) + result = testdir.runpytest("-k=-test_two", threepass) + result.stdout.fnmatch_lines(["*The `-k '-expr'` syntax*deprecated*"]) + + +def test_minus_k_colon_is_deprecated(testdir) -> None: + threepass = testdir.makepyfile( + test_threepass=""" + def test_one(): assert 1 + def test_two(): assert 1 + def test_three(): assert 1 + """ + ) + result = testdir.runpytest("-k", "test_two:", threepass) + result.stdout.fnmatch_lines(["*The `-k 'expr:'` syntax*deprecated*"]) |