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

Method test_conftest

testing/test_collection.py:1422–1439  ·  view source on GitHub ↗

Directory containing conftest modules are not put in sys.path as a side-effect of importing them.

(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

1420 )
1421
1422 def test_conftest(self, pytester: Pytester) -> None:
1423 """Directory containing conftest modules are not put in sys.path as a side-effect of
1424 importing them."""
1425 tests_dir = pytester.path.joinpath("tests")
1426 pytester.makepyfile(
1427 **{
1428 "tests/conftest.py": "",
1429 "tests/test_foo.py": """
1430 import sys
1431 def test_check():
1432 assert r"{tests_dir}" not in sys.path
1433 """.format(
1434 tests_dir=tests_dir
1435 ),
1436 }
1437 )
1438 result = pytester.runpytest("-v", "--import-mode=importlib")
1439 result.stdout.fnmatch_lines(["* 1 passed in *"])
1440
1441 def setup_conftest_and_foo(self, pytester: Pytester) -> None:
1442 """Setup a tests folder to be used to test if modules in that folder can be imported

Callers

nothing calls this directly

Calls 4

fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
formatMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected