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

Function test_conftest_global_import

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

Source from the content-addressed store, hash-verified

152
153
154def test_conftest_global_import(pytester: Pytester) -> None:
155 pytester.makeconftest("x=3")
156 p = pytester.makepyfile(
157 """
158 from pathlib import Path
159 import pytest
160 from _pytest.config import PytestPluginManager
161 conf = PytestPluginManager()
162 mod = conf._importconftest(Path("conftest.py"), importmode="prepend", rootpath=Path.cwd())
163 assert mod.x == 3
164 import conftest
165 assert conftest is mod, (conftest, mod)
166 sub = Path("sub")
167 sub.mkdir()
168 subconf = sub / "conftest.py"
169 subconf.write_text("y=4")
170 mod2 = conf._importconftest(subconf, importmode="prepend", rootpath=Path.cwd())
171 assert mod != mod2
172 assert mod2.y == 4
173 import conftest
174 assert conftest is mod2, (conftest, mod)
175 """
176 )
177 res = pytester.runpython(p)
178 assert res.ret == 0
179
180
181def test_conftestcutdir(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 3

makeconftestMethod · 0.45
makepyfileMethod · 0.45
runpythonMethod · 0.45

Tested by

no test coverage detected