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

Method test_orphaned_pyc_file

testing/test_assertrewrite.py:1093–1120  ·  view source on GitHub ↗
(self, pytester: Pytester, monkeypatch)

Source from the content-addressed store, hash-verified

1091 assert pytester.runpytest_subprocess().ret == 0
1092
1093 def test_orphaned_pyc_file(self, pytester: Pytester, monkeypatch) -> None:
1094 monkeypatch.delenv("PYTHONPYCACHEPREFIX", raising=False)
1095 monkeypatch.setattr(sys, "pycache_prefix", None, raising=False)
1096
1097 pytester.makepyfile(
1098 """
1099 import orphan
1100 def test_it():
1101 assert orphan.value == 17
1102 """
1103 )
1104 pytester.makepyfile(
1105 orphan="""
1106 value = 17
1107 """
1108 )
1109 py_compile.compile("orphan.py")
1110 os.remove("orphan.py")
1111
1112 # Python 3 puts the .pyc files in a __pycache__ directory, and will
1113 # not import from there without source. It will import a .pyc from
1114 # the source location though.
1115 if not os.path.exists("orphan.pyc"):
1116 pycs = glob.glob("__pycache__/orphan.*.pyc")
1117 assert len(pycs) == 1
1118 os.rename(pycs[0], "orphan.pyc")
1119
1120 assert pytester.runpytest().ret == 0
1121
1122 def test_cached_pyc_includes_pytest_version(
1123 self, pytester: Pytester, monkeypatch

Callers

nothing calls this directly

Calls 8

delenvMethod · 0.80
setattrMethod · 0.80
compileMethod · 0.80
removeMethod · 0.80
renameMethod · 0.80
makepyfileMethod · 0.45
existsMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected