MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_fixture_param_shadowing

Function test_fixture_param_shadowing

testing/python/fixtures.py:4297–4337  ·  view source on GitHub ↗

Parametrized arguments would be shadowed if a fixture with the same name also exists (#5036)

(pytester: Pytester)

Source from the content-addressed store, hash-verified

4295
4296
4297def test_fixture_param_shadowing(pytester: Pytester) -> None:
4298 """Parametrized arguments would be shadowed if a fixture with the same name also exists (#5036)"""
4299 pytester.makepyfile(
4300 """
4301 import pytest
4302
4303 @pytest.fixture(params=['a', 'b'])
4304 def argroot(request):
4305 return request.param
4306
4307 @pytest.fixture
4308 def arg(argroot):
4309 return argroot
4310
4311 # This should only be parametrized directly
4312 @pytest.mark.parametrize("arg", [1])
4313 def test_direct(arg):
4314 assert arg == 1
4315
4316 # This should be parametrized based on the fixtures
4317 def test_normal_fixture(arg):
4318 assert isinstance(arg, str)
4319
4320 # Indirect should still work:
4321
4322 @pytest.fixture
4323 def arg2(request):
4324 return 2*request.param
4325
4326 @pytest.mark.parametrize("arg2", [1], indirect=True)
4327 def test_indirect(arg2):
4328 assert arg2 == 2
4329 """
4330 )
4331 # Only one test should have run
4332 result = pytester.runpytest("-v")
4333 result.assert_outcomes(passed=4)
4334 result.stdout.fnmatch_lines(["*::test_direct[[]1[]]*"])
4335 result.stdout.fnmatch_lines(["*::test_normal_fixture[[]a[]]*"])
4336 result.stdout.fnmatch_lines(["*::test_normal_fixture[[]b[]]*"])
4337 result.stdout.fnmatch_lines(["*::test_indirect[[]1[]]*"])
4338
4339
4340def test_fixture_named_request(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 4

assert_outcomesMethod · 0.80
fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected