(self, pytester: Pytester)
| 2443 | ) |
| 2444 | |
| 2445 | def test_dynamic_scope(self, pytester: Pytester) -> None: |
| 2446 | pytester.makeconftest( |
| 2447 | """ |
| 2448 | import pytest |
| 2449 | |
| 2450 | |
| 2451 | def pytest_addoption(parser): |
| 2452 | parser.addoption("--extend-scope", action="store_true", default=False) |
| 2453 | |
| 2454 | |
| 2455 | def dynamic_scope(fixture_name, config): |
| 2456 | if config.getoption("--extend-scope"): |
| 2457 | return "session" |
| 2458 | return "function" |
| 2459 | |
| 2460 | |
| 2461 | @pytest.fixture(scope=dynamic_scope) |
| 2462 | def dynamic_fixture(calls=[]): |
| 2463 | calls.append("call") |
| 2464 | return len(calls) |
| 2465 | |
| 2466 | """ |
| 2467 | ) |
| 2468 | |
| 2469 | pytester.makepyfile( |
| 2470 | """ |
| 2471 | def test_first(dynamic_fixture): |
| 2472 | assert dynamic_fixture == 1 |
| 2473 | |
| 2474 | |
| 2475 | def test_second(dynamic_fixture): |
| 2476 | assert dynamic_fixture == 2 |
| 2477 | |
| 2478 | """ |
| 2479 | ) |
| 2480 | |
| 2481 | reprec = pytester.inline_run() |
| 2482 | reprec.assertoutcome(passed=2) |
| 2483 | |
| 2484 | reprec = pytester.inline_run("--extend-scope") |
| 2485 | reprec.assertoutcome(passed=1, failed=1) |
| 2486 | |
| 2487 | def test_dynamic_scope_bad_return(self, pytester: Pytester) -> None: |
| 2488 | pytester.makepyfile( |
nothing calls this directly
no test coverage detected