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

Function test_setup_only_available_in_subdir

testing/python/collect.py:959–991  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

957
958
959def test_setup_only_available_in_subdir(pytester: Pytester) -> None:
960 sub1 = pytester.mkpydir("sub1")
961 sub2 = pytester.mkpydir("sub2")
962 sub1.joinpath("conftest.py").write_text(
963 textwrap.dedent(
964 """\
965 import pytest
966 def pytest_runtest_setup(item):
967 assert item.path.stem == "test_in_sub1"
968 def pytest_runtest_call(item):
969 assert item.path.stem == "test_in_sub1"
970 def pytest_runtest_teardown(item):
971 assert item.path.stem == "test_in_sub1"
972 """
973 )
974 )
975 sub2.joinpath("conftest.py").write_text(
976 textwrap.dedent(
977 """\
978 import pytest
979 def pytest_runtest_setup(item):
980 assert item.path.stem == "test_in_sub2"
981 def pytest_runtest_call(item):
982 assert item.path.stem == "test_in_sub2"
983 def pytest_runtest_teardown(item):
984 assert item.path.stem == "test_in_sub2"
985 """
986 )
987 )
988 sub1.joinpath("test_in_sub1.py").write_text("def test_1(): pass")
989 sub2.joinpath("test_in_sub2.py").write_text("def test_2(): pass")
990 result = pytester.runpytest("-v", "-s")
991 result.assert_outcomes(passed=2)
992
993
994def test_modulecol_roundtrip(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 3

assert_outcomesMethod · 0.80
mkpydirMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected