| 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 |