Remove deprecated `-k foobar:` syntax

This commit is contained in:
Ran Benita 2021-12-07 22:13:58 +02:00
parent 927d9d274f
commit 4a45a5e983
5 changed files with 2 additions and 51 deletions

View File

@ -37,11 +37,6 @@ YIELD_FIXTURE = PytestDeprecationWarning(
"Use @pytest.fixture instead; they are the same." "Use @pytest.fixture instead; they are the same."
) )
MINUS_K_COLON = PytestRemovedIn7Warning(
"The `-k 'expr:'` syntax to -k is deprecated.\n"
"Please open an issue if you use this and want a replacement."
)
WARNING_CMDLINE_PREPARSE_HOOK = PytestRemovedIn8Warning( WARNING_CMDLINE_PREPARSE_HOOK = PytestRemovedIn8Warning(
"The pytest_cmdline_preparse hook is deprecated and will be removed in a future release. \n" "The pytest_cmdline_preparse hook is deprecated and will be removed in a future release. \n"
"Please use pytest_load_initial_conftests hook instead." "Please use pytest_load_initial_conftests hook instead."

View File

@ -1,5 +1,4 @@
"""Generic mechanism for marking and selecting python functions.""" """Generic mechanism for marking and selecting python functions."""
import warnings
from typing import AbstractSet from typing import AbstractSet
from typing import Collection from typing import Collection
from typing import List from typing import List
@ -23,7 +22,6 @@ from _pytest.config import ExitCode
from _pytest.config import hookimpl from _pytest.config import hookimpl
from _pytest.config import UsageError from _pytest.config import UsageError
from _pytest.config.argparsing import Parser from _pytest.config.argparsing import Parser
from _pytest.deprecated import MINUS_K_COLON
from _pytest.stash import StashKey from _pytest.stash import StashKey
if TYPE_CHECKING: if TYPE_CHECKING:
@ -188,23 +186,14 @@ def deselect_by_keyword(items: "List[Item]", config: Config) -> None:
if not keywordexpr: if not keywordexpr:
return return
selectuntil = False
if keywordexpr[-1:] == ":":
# To be removed in pytest 8.0.0.
warnings.warn(MINUS_K_COLON, stacklevel=2)
selectuntil = True
keywordexpr = keywordexpr[:-1]
expr = _parse_expression(keywordexpr, "Wrong expression passed to '-k'") expr = _parse_expression(keywordexpr, "Wrong expression passed to '-k'")
remaining = [] remaining = []
deselected = [] deselected = []
for colitem in items: for colitem in items:
if keywordexpr and not expr.evaluate(KeywordMatcher.from_item(colitem)): if not expr.evaluate(KeywordMatcher.from_item(colitem)):
deselected.append(colitem) deselected.append(colitem)
else: else:
if selectuntil:
keywordexpr = None
remaining.append(colitem) remaining.append(colitem)
if deselected: if deselected:

View File

@ -27,18 +27,6 @@ def test_external_plugins_integrated(pytester: Pytester, plugin) -> None:
pytester.parseconfig("-p", plugin) pytester.parseconfig("-p", plugin)
def test_minus_k_colon_is_deprecated(pytester: Pytester) -> None:
threepass = pytester.makepyfile(
test_threepass="""
def test_one(): assert 1
def test_two(): assert 1
def test_three(): assert 1
"""
)
result = pytester.runpytest("-k", "test_two:", threepass)
result.stdout.fnmatch_lines(["*The `-k 'expr:'` syntax*deprecated*"])
def test_fscollector_gethookproxy_isinitpath(pytester: Pytester) -> None: def test_fscollector_gethookproxy_isinitpath(pytester: Pytester) -> None:
module = pytester.getmodulecol( module = pytester.getmodulecol(
""" """

View File

@ -823,25 +823,6 @@ class TestKeywordSelection:
assert len(dlist) == 1 assert len(dlist) == 1
assert dlist[0].items[0].name == "test_1" assert dlist[0].items[0].name == "test_1"
def test_select_starton(self, pytester: Pytester) -> None:
threepass = pytester.makepyfile(
test_threepass="""
def test_one(): assert 1
def test_two(): assert 1
def test_three(): assert 1
"""
)
reprec = pytester.inline_run(
"-Wignore::pytest.PytestRemovedIn7Warning", "-k", "test_two:", threepass
)
passed, skipped, failed = reprec.listoutcomes()
assert len(passed) == 2
assert not failed
dlist = reprec.getcalls("pytest_deselected")
assert len(dlist) == 1
item = dlist[0].items[0]
assert item.name == "test_one"
def test_keyword_extra(self, pytester: Pytester) -> None: def test_keyword_extra(self, pytester: Pytester) -> None:
p = pytester.makepyfile( p = pytester.makepyfile(
""" """

View File

@ -682,9 +682,7 @@ class TestTerminalFunctional:
pass pass
""" """
) )
result = pytester.runpytest( result = pytester.runpytest("-k", "test_t", testpath)
"-Wignore::pytest.PytestRemovedIn7Warning", "-k", "test_two:", testpath
)
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
["collected 3 items / 1 deselected / 2 selected", "*test_deselected.py ..*"] ["collected 3 items / 1 deselected / 2 selected", "*test_deselected.py ..*"]
) )