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

Method test_dynamic_scope

testing/python/fixtures.py:2445–2485  ·  view source on GitHub ↗
(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

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(

Callers

nothing calls this directly

Calls 4

assertoutcomeMethod · 0.80
makeconftestMethod · 0.45
makepyfileMethod · 0.45
inline_runMethod · 0.45

Tested by

no test coverage detected