fix issue357 - special case "-k" expressions to allow for
filtering with simple strings that are not valid python expressions. Examples: "-k 1.3" matches all tests parametrized with 1.3. "-k None" filters all tests that have "None" in their name and conversely "-k 'not None'". Previously these examples would raise syntax errors. Also add a note to the docs about what is allowed.
This commit is contained in:
+23
-1
@@ -174,7 +174,9 @@ def test_mark_option_custom(spec, testdir):
|
||||
|
||||
@pytest.mark.parametrize("spec", [
|
||||
("interface", ("test_interface",)),
|
||||
("not interface", ("test_nointer",)),
|
||||
("not interface", ("test_nointer", "test_pass")),
|
||||
("pass", ("test_pass",)),
|
||||
("not pass", ("test_interface", "test_nointer")),
|
||||
])
|
||||
def test_keyword_option_custom(spec, testdir):
|
||||
testdir.makepyfile("""
|
||||
@@ -182,6 +184,8 @@ def test_keyword_option_custom(spec, testdir):
|
||||
pass
|
||||
def test_nointer():
|
||||
pass
|
||||
def test_pass():
|
||||
pass
|
||||
""")
|
||||
opt, passed_result = spec
|
||||
rec = testdir.inline_run("-k", opt)
|
||||
@@ -191,6 +195,24 @@ def test_keyword_option_custom(spec, testdir):
|
||||
assert list(passed) == list(passed_result)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("spec", [
|
||||
("None", ("test_func[None]",)),
|
||||
("1.3", ("test_func[1.3]",))
|
||||
])
|
||||
def test_keyword_option_parametrize(spec, testdir):
|
||||
testdir.makepyfile("""
|
||||
import pytest
|
||||
@pytest.mark.parametrize("arg", [None, 1.3])
|
||||
def test_func(arg):
|
||||
pass
|
||||
""")
|
||||
opt, passed_result = spec
|
||||
rec = testdir.inline_run("-k", opt)
|
||||
passed, skipped, fail = rec.listoutcomes()
|
||||
passed = [x.nodeid.split("::")[-1] for x in passed]
|
||||
assert len(passed) == len(passed_result)
|
||||
assert list(passed) == list(passed_result)
|
||||
|
||||
class TestFunctional:
|
||||
|
||||
def test_mark_per_function(self, testdir):
|
||||
|
||||
Reference in New Issue
Block a user