|
23 | 23 | from _pytest.compat import NOTSET
|
24 | 24 | from _pytest.outcomes import fail
|
25 | 25 | from _pytest.pytester import Pytester
|
| 26 | +from _pytest.python import Function |
26 | 27 | from _pytest.python import IdMaker
|
27 | 28 | from _pytest.scope import Scope
|
28 | 29 |
|
@@ -974,16 +975,6 @@ def test_parametrize_twoargs(self) -> None:
|
974 | 975 | assert metafunc._calls[1].params == dict(x=3, y=4)
|
975 | 976 | assert metafunc._calls[1].id == "3-4"
|
976 | 977 |
|
977 |
| - @pytest.mark.xfail(reason="Will pass upon merging PR#11257") |
978 |
| - def test_parametrize_with_duplicate_values(self) -> None: |
979 |
| - metafunc = self.Metafunc(lambda x, y: None) |
980 |
| - metafunc.parametrize(("x", "y"), [(1, 2), (3, 4), (1, 5), (2, 2)]) |
981 |
| - assert len(metafunc._calls) == 4 |
982 |
| - assert metafunc._calls[0].indices == dict(x=0, y=0) |
983 |
| - assert metafunc._calls[1].indices == dict(x=1, y=1) |
984 |
| - assert metafunc._calls[2].indices == dict(x=0, y=2) |
985 |
| - assert metafunc._calls[3].indices == dict(x=2, y=0) |
986 |
| - |
987 | 978 | def test_high_scoped_parametrize_reordering(self, pytester: Pytester) -> None:
|
988 | 979 | pytester.makepyfile(
|
989 | 980 | """
|
@@ -1018,36 +1009,6 @@ def test3(arg1):
|
1018 | 1009 | ]
|
1019 | 1010 | )
|
1020 | 1011 |
|
1021 |
| - @pytest.mark.xfail(reason="Will pass upon merging PR#11257") |
1022 |
| - def test_high_scoped_parametrize_with_duplicate_values_reordering( |
1023 |
| - self, pytester: Pytester |
1024 |
| - ) -> None: |
1025 |
| - pytester.makepyfile( |
1026 |
| - """ |
1027 |
| - import pytest |
1028 |
| -
|
1029 |
| - @pytest.fixture(scope='module') |
1030 |
| - def fixture1(request): |
1031 |
| - pass |
1032 |
| -
|
1033 |
| - @pytest.fixture(scope='module') |
1034 |
| - def fixture2(request): |
1035 |
| - pass |
1036 |
| -
|
1037 |
| - @pytest.mark.parametrize("fixture1, fixture2", [("a", 0), ("b", 1), ("a", 2)], indirect=True) |
1038 |
| - def test(fixture1, fixture2): |
1039 |
| - pass |
1040 |
| - """ |
1041 |
| - ) |
1042 |
| - result = pytester.runpytest("--collect-only") |
1043 |
| - result.stdout.re_match_lines( |
1044 |
| - [ |
1045 |
| - r" <Function test\[a-0\]>", |
1046 |
| - r" <Function test\[a-2\]>", |
1047 |
| - r" <Function test\[b-1\]>", |
1048 |
| - ] |
1049 |
| - ) |
1050 |
| - |
1051 | 1012 | def test_parametrize_multiple_times(self, pytester: Pytester) -> None:
|
1052 | 1013 | pytester.makepyfile(
|
1053 | 1014 | """
|
@@ -1590,29 +1551,27 @@ def test_it(x): pass
|
1590 | 1551 | def test_parametrize_module_level_test_with_class_scope(
|
1591 | 1552 | self, pytester: Pytester
|
1592 | 1553 | ) -> None:
|
1593 |
| - pytester.makepyfile( |
| 1554 | + module = pytester.makepyfile( |
1594 | 1555 | """
|
1595 | 1556 | import pytest
|
1596 | 1557 |
|
1597 |
| - @pytest.fixture |
1598 |
| - def item(request): |
1599 |
| - return request._pyfuncitem |
1600 |
| -
|
1601 |
| - fixturedef = None |
1602 |
| -
|
1603 | 1558 | @pytest.mark.parametrize("x", [0, 1], scope="class")
|
1604 |
| - def test_1(item, x): |
1605 |
| - global fixturedef |
1606 |
| - fixturedef = item._fixtureinfo.name2fixturedefs['x'][-1] |
| 1559 | + def test_1(x): |
| 1560 | + pass |
1607 | 1561 |
|
1608 | 1562 | @pytest.mark.parametrize("x", [1, 2], scope="module")
|
1609 |
| - def test_2(item, x): |
1610 |
| - global fixturedef |
1611 |
| - assert fixturedef == item._fixtureinfo.name2fixturedefs['x'][-1] |
| 1563 | + def test_2(x): |
| 1564 | + pass |
1612 | 1565 | """
|
1613 | 1566 | )
|
1614 |
| - result = pytester.runpytest() |
1615 |
| - assert result.ret == 0 |
| 1567 | + test_1_0, _, test_2_0, _ = pytester.genitems((pytester.getmodulecol(module),)) |
| 1568 | + test_1_fixture_x = cast(Function, test_1_0)._fixtureinfo.name2fixturedefs["x"][ |
| 1569 | + -1 |
| 1570 | + ] |
| 1571 | + test_2_fixture_x = cast(Function, test_2_0)._fixtureinfo.name2fixturedefs["x"][ |
| 1572 | + -1 |
| 1573 | + ] |
| 1574 | + assert test_1_fixture_x == test_2_fixture_x |
1616 | 1575 |
|
1617 | 1576 |
|
1618 | 1577 | class TestMetafuncFunctionalAuto:
|
|
0 commit comments