MCPcopy
hub / github.com/pytest-dev/pytest / test_conftest_global_import

Function test_conftest_global_import

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

Source from the content-addressed store, hash-verified

163
164
165def test_conftest_global_import(pytester: Pytester) -> None:
166 pytester.makeconftest("x=3")
167 p = pytester.makepyfile(
168 """
169 from pathlib import Path
170 import pytest
171 from _pytest.config import PytestPluginManager
172 conf = PytestPluginManager()
173 mod = conf._importconftest(
174 Path("conftest.py"),
175 importmode="prepend",
176 rootpath=Path.cwd(),
177 consider_namespace_packages=False,
178 )
179 assert mod.x == 3
180 import conftest
181 assert conftest is mod, (conftest, mod)
182 sub = Path("sub")
183 sub.mkdir()
184 subconf = sub / "conftest.py"
185 subconf.write_text("y=4", encoding="utf-8")
186 mod2 = conf._importconftest(
187 subconf,
188 importmode="prepend",
189 rootpath=Path.cwd(),
190 consider_namespace_packages=False,
191 )
192 assert mod != mod2
193 assert mod2.y == 4
194 import conftest
195 assert conftest is mod2, (conftest, mod)
196 """
197 )
198 res = pytester.runpython(p)
199 assert res.ret == 0
200
201
202def 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