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

Method test_orphaned_pyc_file

testing/test_assertrewrite.py:1093–1120  ·  testing/test_assertrewrite.py::TestRewriteOnImport.test_orphaned_pyc_file
(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(class="st">"PYTHONPYCACHEPREFIX", raising=False)
1095 monkeypatch.setattr(sys, class="st">"pycache_prefix", None, raising=False)
1096
1097 pytester.makepyfile(
1098 class="st">"""
1099 import orphan
1100 def test_it():
1101 assert orphan.value == 17
1102 class="st">"""
1103 )
1104 pytester.makepyfile(
1105 orphan=class="st">"""
1106 value = 17
1107 class="st">"""
1108 )
1109 py_compile.compile(class="st">"orphan.py")
1110 os.remove(class="st">"orphan.py")
1111
1112 class="cm"># Python 3 puts the .pyc files in a __pycache__ directory, and will
1113 class="cm"># not import from there without source. It will import a .pyc from
1114 class="cm"># the source location though.
1115 if not os.path.exists(class="st">"orphan.pyc"):
1116 pycs = glob.glob(class="st">"__pycache__/orphan.*.pyc")
1117 assert len(pycs) == 1
1118 os.rename(pycs[0], class="st">"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