Improve a test
This commit is contained in:
parent
81464b3e68
commit
2c270b8fbb
|
@ -4538,51 +4538,57 @@ def test_yield_fixture_with_no_value(pytester: Pytester) -> None:
|
||||||
assert result.ret == ExitCode.TESTS_FAILED
|
assert result.ret == ExitCode.TESTS_FAILED
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("scope", ["module", "package"])
|
||||||
def test_basing_fixture_argkeys_on_param_values_rather_than_on_param_indices(
|
def test_basing_fixture_argkeys_on_param_values_rather_than_on_param_indices(
|
||||||
|
scope,
|
||||||
pytester: Pytester,
|
pytester: Pytester,
|
||||||
):
|
):
|
||||||
pytester.makepyfile(
|
package = pytester.mkdir("package")
|
||||||
"""
|
package.joinpath("__init__.py").write_text("")
|
||||||
import pytest
|
package.joinpath("test_a.py").write_text(
|
||||||
|
textwrap.dedent(
|
||||||
|
f"""\
|
||||||
|
import pytest
|
||||||
|
|
||||||
@pytest.fixture(scope='module')
|
@pytest.fixture(scope='{scope}')
|
||||||
def fixture1(request):
|
def fixture1(request):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@pytest.mark.parametrize("fixture1",[1, 0],indirect=True)
|
@pytest.mark.parametrize("fixture1", [1, 0], indirect=True)
|
||||||
def test_0(fixture1):
|
def test_0(fixture1):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@pytest.mark.parametrize("fixture1",[2, 1],indirect=True)
|
@pytest.mark.parametrize("fixture1", [2, 1], indirect=True)
|
||||||
def test_1(fixture1):
|
def test_1(fixture1):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_2():
|
def test_2():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@pytest.mark.parametrize("param", [0,1,2], scope='module')
|
@pytest.mark.parametrize("param", [0, 1, 2], scope='{scope}')
|
||||||
def test_3(param):
|
def test_3(param):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@pytest.mark.parametrize("param", [2,1,0], scope='module')
|
@pytest.mark.parametrize("param", [2, 1, 0], scope='{scope}')
|
||||||
def test_4(param):
|
def test_4(param):
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
|
),
|
||||||
)
|
)
|
||||||
result = pytester.runpytest("--collect-only")
|
result = pytester.runpytest("--collect-only")
|
||||||
result.stdout.re_match_lines(
|
result.stdout.re_match_lines(
|
||||||
[
|
[
|
||||||
r" <Function test_0\[1\]>",
|
r" <Function test_0\[1\]>",
|
||||||
r" <Function test_1\[1\]>",
|
r" <Function test_1\[1\]>",
|
||||||
r" <Function test_0\[0\]>",
|
r" <Function test_0\[0\]>",
|
||||||
r" <Function test_1\[2\]>",
|
r" <Function test_1\[2\]>",
|
||||||
r" <Function test_2>",
|
r" <Function test_2>",
|
||||||
r" <Function test_3\[0\]>",
|
r" <Function test_3\[0\]>",
|
||||||
r" <Function test_4\[0\]>",
|
r" <Function test_4\[0\]>",
|
||||||
r" <Function test_3\[1\]>",
|
r" <Function test_3\[1\]>",
|
||||||
r" <Function test_4\[1\]>",
|
r" <Function test_4\[1\]>",
|
||||||
r" <Function test_3\[2\]>",
|
r" <Function test_3\[2\]>",
|
||||||
r" <Function test_4\[2\]>",
|
r" <Function test_4\[2\]>",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue