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

Function test_collect_with_chdir_during_import

testing/test_collection.py:1142–1175  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

1140
1141
1142def test_collect_with_chdir_during_import(pytester: Pytester) -> None:
1143 subdir = pytester.mkdir("sub")
1144 pytester.path.joinpath("conftest.py").write_text(
1145 textwrap.dedent(
1146 """
1147 import os
1148 os.chdir(%r)
1149 """
1150 % (str(subdir),)
1151 )
1152 )
1153 pytester.makepyfile(
1154 """
1155 def test_1():
1156 import os
1157 assert os.getcwd() == %r
1158 """
1159 % (str(subdir),)
1160 )
1161 with pytester.path.cwd():
1162 result = pytester.runpytest()
1163 result.stdout.fnmatch_lines(["*1 passed in*"])
1164 assert result.ret == 0
1165
1166 # Handles relative testpaths.
1167 pytester.makeini(
1168 """
1169 [pytest]
1170 testpaths = .
1171 """
1172 )
1173 with pytester.path.cwd():
1174 result = pytester.runpytest("--collect-only")
1175 result.stdout.fnmatch_lines(["collected 1 item"])
1176
1177
1178def test_collect_pyargs_with_testpaths(

Callers

nothing calls this directly

Calls 5

fnmatch_linesMethod · 0.80
mkdirMethod · 0.45
makepyfileMethod · 0.45
runpytestMethod · 0.45
makeiniMethod · 0.45

Tested by

no test coverage detected