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

Method test_testpaths_ini

testing/test_collection.py:228–262  ·  view source on GitHub ↗
(self, pytester: Pytester, monkeypatch: MonkeyPatch)

Source from the content-addressed store, hash-verified

226 rec.assertoutcome(failed=1)
227
228 def test_testpaths_ini(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
229 pytester.makeini(
230 """
231 [pytest]
232 testpaths = */tests
233 """
234 )
235 tmp_path = pytester.path
236 ensure_file(tmp_path / "a" / "test_1.py").write_text(
237 "def test_a(): pass", encoding="utf-8"
238 )
239 ensure_file(tmp_path / "b" / "tests" / "test_2.py").write_text(
240 "def test_b(): pass", encoding="utf-8"
241 )
242 ensure_file(tmp_path / "c" / "tests" / "test_3.py").write_text(
243 "def test_c(): pass", encoding="utf-8"
244 )
245
246 # executing from rootdir only tests from `testpaths` directories
247 # are collected
248 items, _reprec = pytester.inline_genitems("-v")
249 assert [x.name for x in items] == ["test_b", "test_c"]
250
251 # check that explicitly passing directories in the command-line
252 # collects the tests
253 for dirname in ("a", "b", "c"):
254 items, _reprec = pytester.inline_genitems(tmp_path.joinpath(dirname))
255 assert [x.name for x in items] == [f"test_{dirname}"]
256
257 # changing cwd to each subdirectory and running pytest without
258 # arguments collects the tests in that directory normally
259 for dirname in ("a", "b", "c"):
260 monkeypatch.chdir(pytester.path.joinpath(dirname))
261 items, _reprec = pytester.inline_genitems()
262 assert [x.name for x in items] == [f"test_{dirname}"]
263
264 def test_missing_permissions_on_unselected_directory_doesnt_crash(
265 self, pytester: Pytester

Callers

nothing calls this directly

Calls 5

ensure_fileFunction · 0.85
write_textMethod · 0.80
makeiniMethod · 0.45
inline_genitemsMethod · 0.45
chdirMethod · 0.45

Tested by

no test coverage detected