mark: deprecate a couple undocumented -k syntaxes
The `-k '-expr'` syntax is an old alias to `-k 'not expr'`. It's also not a very convenient to have syntax that start with `-` on the CLI. Deprecate it and suggest replacing with `not`. --- The `-k 'expr:'` syntax discards all items until the first match and keeps all subsequent, e.g. `-k foo` with test_bar test_foo test_baz results in `test_foo`, `test_baz`. That's a bit weird, so deprecate it without a replacement. If someone complains we can reconsider or devise a better alternative.
This commit is contained in:
parent
5e7f1ab4bf
commit
c4f9eaa5de
|
@ -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.
|
|
@ -75,3 +75,13 @@ TERMINALWRITER_WRITER = PytestDeprecationWarning(
|
||||||
"The TerminalReporter.writer attribute is deprecated, use TerminalReporter._tw instead at your own risk.\n"
|
"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."
|
"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."
|
||||||
|
)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
""" generic mechanism for marking and selecting python functions. """
|
""" generic mechanism for marking and selecting python functions. """
|
||||||
|
import warnings
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from .legacy import matchkeyword
|
from .legacy import matchkeyword
|
||||||
|
@ -13,6 +14,8 @@ from .structures import ParameterSet
|
||||||
from _pytest.config import Config
|
from _pytest.config import Config
|
||||||
from _pytest.config import hookimpl
|
from _pytest.config import hookimpl
|
||||||
from _pytest.config import UsageError
|
from _pytest.config import UsageError
|
||||||
|
from _pytest.deprecated import MINUS_K_COLON
|
||||||
|
from _pytest.deprecated import MINUS_K_DASH
|
||||||
from _pytest.store import StoreKey
|
from _pytest.store import StoreKey
|
||||||
|
|
||||||
__all__ = ["Mark", "MarkDecorator", "MarkGenerator", "get_empty_parameterset_mark"]
|
__all__ = ["Mark", "MarkDecorator", "MarkGenerator", "get_empty_parameterset_mark"]
|
||||||
|
@ -107,9 +110,13 @@ def deselect_by_keyword(items, config):
|
||||||
return
|
return
|
||||||
|
|
||||||
if keywordexpr.startswith("-"):
|
if keywordexpr.startswith("-"):
|
||||||
|
# To be removed in pytest 7.0.0.
|
||||||
|
warnings.warn(MINUS_K_DASH, stacklevel=2)
|
||||||
keywordexpr = "not " + keywordexpr[1:]
|
keywordexpr = "not " + keywordexpr[1:]
|
||||||
selectuntil = False
|
selectuntil = False
|
||||||
if keywordexpr[-1:] == ":":
|
if keywordexpr[-1:] == ":":
|
||||||
|
# To be removed in pytest 7.0.0.
|
||||||
|
warnings.warn(MINUS_K_COLON, stacklevel=2)
|
||||||
selectuntil = True
|
selectuntil = True
|
||||||
keywordexpr = keywordexpr[:-1]
|
keywordexpr = keywordexpr[:-1]
|
||||||
|
|
||||||
|
|
|
@ -164,3 +164,27 @@ def test__fillfuncargs_is_deprecated() -> None:
|
||||||
match="The `_fillfuncargs` function is deprecated",
|
match="The `_fillfuncargs` function is deprecated",
|
||||||
):
|
):
|
||||||
pytest._fillfuncargs(mock.Mock())
|
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*"])
|
||||||
|
|
Loading…
Reference in New Issue