(pytester: Pytester)
| 152 | |
| 153 | |
| 154 | def 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 | |
| 181 | def test_conftestcutdir(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected