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

Function test_fixture_dependency

testing/test_conftest.py:399–441  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

397
398
399def test_fixture_dependency(pytester: Pytester) -> None:
400 pytester.makeconftest("")
401 pytester.path.joinpath("__init__.py").touch()
402 sub = pytester.mkdir("sub")
403 sub.joinpath("__init__.py").touch()
404 sub.joinpath("conftest.py").write_text(
405 textwrap.dedent(
406 """\
407 import pytest
408
409 @pytest.fixture
410 def not_needed():
411 assert False, "Should not be called!"
412
413 @pytest.fixture
414 def foo():
415 assert False, "Should not be called!"
416
417 @pytest.fixture
418 def bar(foo):
419 return 'bar'
420 """
421 )
422 )
423 subsub = sub.joinpath("subsub")
424 subsub.mkdir()
425 subsub.joinpath("__init__.py").touch()
426 subsub.joinpath("test_bar.py").write_text(
427 textwrap.dedent(
428 """\
429 import pytest
430
431 @pytest.fixture
432 def bar():
433 return 'sub bar'
434
435 def test_event_fixture(bar):
436 assert bar == 'sub bar'
437 """
438 )
439 )
440 result = pytester.runpytest("sub")
441 result.stdout.fnmatch_lines(["*1 passed*"])
442
443
444def test_conftest_found_with_double_dash(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 4

fnmatch_linesMethod · 0.80
makeconftestMethod · 0.45
mkdirMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected