Skip to content

Commit

Permalink
testing: clean up parametrization in test_mark.py (#7184)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluetech committed May 7, 2020
1 parent 32c00db commit de556f8
Showing 1 changed file with 40 additions and 45 deletions.
85 changes: 40 additions & 45 deletions testing/test_mark.py
Expand Up @@ -197,17 +197,17 @@ def test_hello():


@pytest.mark.parametrize(
"spec",
("expr", "expected_passed"),
[
("xyz", ("test_one",)),
("((( xyz)) )", ("test_one",)),
("not not xyz", ("test_one",)),
("xyz and xyz2", ()),
("xyz2", ("test_two",)),
("xyz or xyz2", ("test_one", "test_two")),
("xyz", ["test_one"]),
("((( xyz)) )", ["test_one"]),
("not not xyz", ["test_one"]),
("xyz and xyz2", []),
("xyz2", ["test_two"]),
("xyz or xyz2", ["test_one", "test_two"]),
],
)
def test_mark_option(spec, testdir):
def test_mark_option(expr: str, expected_passed: str, testdir) -> None:
testdir.makepyfile(
"""
import pytest
Expand All @@ -219,18 +219,17 @@ def test_two():
pass
"""
)
opt, passed_result = spec
rec = testdir.inline_run("-m", opt)
rec = testdir.inline_run("-m", expr)
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)
assert passed == expected_passed


@pytest.mark.parametrize(
"spec", [("interface", ("test_interface",)), ("not interface", ("test_nointer",))]
("expr", "expected_passed"),
[("interface", ["test_interface"]), ("not interface", ["test_nointer"])],
)
def test_mark_option_custom(spec, testdir):
def test_mark_option_custom(expr: str, expected_passed: str, testdir) -> None:
testdir.makeconftest(
"""
import pytest
Expand All @@ -248,26 +247,25 @@ def test_nointer():
pass
"""
)
opt, passed_result = spec
rec = testdir.inline_run("-m", opt)
rec = testdir.inline_run("-m", expr)
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)
assert passed == expected_passed


@pytest.mark.parametrize(
"spec",
("expr", "expected_passed"),
[
("interface", ("test_interface",)),
("not interface", ("test_nointer", "test_pass", "test_1", "test_2")),
("pass", ("test_pass",)),
("not pass", ("test_interface", "test_nointer", "test_1", "test_2")),
("not not not (pass)", ("test_interface", "test_nointer", "test_1", "test_2")),
("1 or 2", ("test_1", "test_2")),
("interface", ["test_interface"]),
("not interface", ["test_nointer", "test_pass", "test_1", "test_2"]),
("pass", ["test_pass"]),
("not pass", ["test_interface", "test_nointer", "test_1", "test_2"]),
("not not not (pass)", ["test_interface", "test_nointer", "test_1", "test_2"]),
("1 or 2", ["test_1", "test_2"]),
("not (1 or 2)", ["test_interface", "test_nointer", "test_pass"]),
],
)
def test_keyword_option_custom(spec, testdir):
def test_keyword_option_custom(expr: str, expected_passed: str, testdir) -> None:
testdir.makepyfile(
"""
def test_interface():
Expand All @@ -282,12 +280,10 @@ def test_2():
pass
"""
)
opt, passed_result = spec
rec = testdir.inline_run("-k", opt)
rec = testdir.inline_run("-k", expr)
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)
assert passed == expected_passed


def test_keyword_option_considers_mark(testdir):
Expand All @@ -298,14 +294,14 @@ def test_keyword_option_considers_mark(testdir):


@pytest.mark.parametrize(
"spec",
("expr", "expected_passed"),
[
("None", ("test_func[None]",)),
("[1.3]", ("test_func[1.3]",)),
("2-3", ("test_func[2-3]",)),
("None", ["test_func[None]"]),
("[1.3]", ["test_func[1.3]"]),
("2-3", ["test_func[2-3]"]),
],
)
def test_keyword_option_parametrize(spec, testdir):
def test_keyword_option_parametrize(expr: str, expected_passed: str, testdir) -> None:
testdir.makepyfile(
"""
import pytest
Expand All @@ -314,12 +310,10 @@ def test_func(arg):
pass
"""
)
opt, passed_result = spec
rec = testdir.inline_run("-k", opt)
rec = testdir.inline_run("-k", expr)
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)
assert passed == expected_passed


def test_parametrize_with_module(testdir):
Expand All @@ -338,7 +332,7 @@ def test_func(arg):


@pytest.mark.parametrize(
"spec",
("expr", "expected_error"),
[
(
"foo or",
Expand All @@ -360,17 +354,18 @@ def test_func(arg):
),
],
)
def test_keyword_option_wrong_arguments(spec, testdir, capsys):
def test_keyword_option_wrong_arguments(
expr: str, expected_error: str, testdir, capsys
) -> None:
testdir.makepyfile(
"""
def test_func(arg):
pass
"""
)
opt, expected_result = spec
testdir.inline_run("-k", opt)
out = capsys.readouterr().err
assert expected_result in out
testdir.inline_run("-k", expr)
err = capsys.readouterr().err
assert expected_error in err


def test_parametrized_collected_from_command_line(testdir):
Expand Down

0 comments on commit de556f8

Please sign in to comment.