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

Method test_import_prepend_append

testing/python/collect.py:45–70  ·  view source on GitHub ↗
(
        self, pytester: Pytester, monkeypatch: MonkeyPatch
    )

Source from the content-addressed store, hash-verified

43 )
44
45 def test_import_prepend_append(
46 self, pytester: Pytester, monkeypatch: MonkeyPatch
47 ) -> None:
48 root1 = pytester.mkdir("root1")
49 root2 = pytester.mkdir("root2")
50 root1.joinpath("x456.py").touch()
51 root2.joinpath("x456.py").touch()
52 p = root2.joinpath("test_x456.py")
53 monkeypatch.syspath_prepend(str(root1))
54 p.write_text(
55 textwrap.dedent(
56 """\
57 import x456
58 def test():
59 assert x456.__file__.startswith({!r})
60 """.format(
61 str(root2)
62 )
63 )
64 )
65 with monkeypatch.context() as mp:
66 mp.chdir(root2)
67 reprec = pytester.inline_run("--import-mode=append")
68 reprec.assertoutcome(passed=0, failed=1)
69 reprec = pytester.inline_run()
70 reprec.assertoutcome(passed=1)
71
72 def test_syntax_error_in_module(self, pytester: Pytester) -> None:
73 modcol = pytester.getmodulecol("this is a syntax error")

Callers

nothing calls this directly

Calls 7

syspath_prependMethod · 0.80
contextMethod · 0.80
assertoutcomeMethod · 0.80
mkdirMethod · 0.45
formatMethod · 0.45
chdirMethod · 0.45
inline_runMethod · 0.45

Tested by

no test coverage detected