Apply comments

This commit is contained in:
Sadra Barikbin 2023-08-02 14:22:46 +03:30
parent 40b2c09ecf
commit 8b59725300
2 changed files with 15 additions and 9 deletions

View File

@ -40,7 +40,6 @@ from _pytest._code.code import Traceback
from _pytest._io import TerminalWriter
from _pytest._io.saferepr import saferepr
from _pytest.compat import ascii_escaped
from _pytest.compat import assert_never
from _pytest.compat import get_default_arg_names
from _pytest.compat import get_real_func
from _pytest.compat import getimfunc
@ -1355,7 +1354,7 @@ class Metafunc:
elif scope_ is Scope.Package:
node = collector.session
else:
assert_never(scope_) # type: ignore[arg-type]
assert False, f"Unhandled missing scope: {scope}"
if node is None:
name2pseudofixturedef = None
else:

View File

@ -1551,6 +1551,10 @@ class TestMetafuncFunctional:
def test_parametrize_module_level_test_with_class_scope(
self, pytester: Pytester
) -> None:
"""
Test that a class-scoped parametrization without a corresponding `Class`
gets module scope, i.e. we only create a single FixtureDef for it per module.
"""
module = pytester.makepyfile(
"""
import pytest
@ -1565,13 +1569,16 @@ class TestMetafuncFunctional:
"""
)
test_1_0, _, test_2_0, _ = pytester.genitems((pytester.getmodulecol(module),))
test_1_fixture_x = cast(Function, test_1_0)._fixtureinfo.name2fixturedefs["x"][
-1
]
test_2_fixture_x = cast(Function, test_2_0)._fixtureinfo.name2fixturedefs["x"][
-1
]
assert test_1_fixture_x == test_2_fixture_x
assert isinstance(test_1_0, Function)
assert test_1_0.name == "test_1[0]"
test_1_fixture_x = test_1_0._fixtureinfo.name2fixturedefs["x"][-1]
assert isinstance(test_2_0, Function)
assert test_2_0.name == "test_2[1]"
test_2_fixture_x = test_2_0._fixtureinfo.name2fixturedefs["x"][-1]
assert test_1_fixture_x is test_2_fixture_x
class TestMetafuncFunctionalAuto: