Ensure that fixture scope is respected when using indirect fixtures (#570)
(pytester: Pytester)
| 4349 | |
| 4350 | |
| 4351 | def test_indirect_fixture_does_not_break_scope(pytester: Pytester) -> None: |
| 4352 | """Ensure that fixture scope is respected when using indirect fixtures (#570)""" |
| 4353 | pytester.makepyfile( |
| 4354 | """ |
| 4355 | import pytest |
| 4356 | instantiated = [] |
| 4357 | |
| 4358 | @pytest.fixture(scope="session") |
| 4359 | def fixture_1(request): |
| 4360 | instantiated.append(("fixture_1", request.param)) |
| 4361 | |
| 4362 | |
| 4363 | @pytest.fixture(scope="session") |
| 4364 | def fixture_2(request): |
| 4365 | instantiated.append(("fixture_2", request.param)) |
| 4366 | |
| 4367 | |
| 4368 | scenarios = [ |
| 4369 | ("A", "a1"), |
| 4370 | ("A", "a2"), |
| 4371 | ("B", "b1"), |
| 4372 | ("B", "b2"), |
| 4373 | ("C", "c1"), |
| 4374 | ("C", "c2"), |
| 4375 | ] |
| 4376 | |
| 4377 | @pytest.mark.parametrize( |
| 4378 | "fixture_1,fixture_2", scenarios, indirect=["fixture_1", "fixture_2"] |
| 4379 | ) |
| 4380 | def test_create_fixtures(fixture_1, fixture_2): |
| 4381 | pass |
| 4382 | |
| 4383 | |
| 4384 | def test_check_fixture_instantiations(): |
| 4385 | assert instantiated == [ |
| 4386 | ('fixture_1', 'A'), |
| 4387 | ('fixture_2', 'a1'), |
| 4388 | ('fixture_2', 'a2'), |
| 4389 | ('fixture_1', 'B'), |
| 4390 | ('fixture_2', 'b1'), |
| 4391 | ('fixture_2', 'b2'), |
| 4392 | ('fixture_1', 'C'), |
| 4393 | ('fixture_2', 'c1'), |
| 4394 | ('fixture_2', 'c2'), |
| 4395 | ] |
| 4396 | """ |
| 4397 | ) |
| 4398 | result = pytester.runpytest() |
| 4399 | result.assert_outcomes(passed=7) |
| 4400 | |
| 4401 | |
| 4402 | def test_fixture_parametrization_nparray(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected