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

Method test_pyc_vs_pyo

testing/test_assertrewrite.py:1142–1166  ·  testing/test_assertrewrite.py::TestRewriteOnImport.test_pyc_vs_pyo
(
        self,
        pytester: Pytester,
        monkeypatch: pytest.MonkeyPatch,
    )

Source from the content-addressed store, hash-verified

1140
1141 @pytest.mark.skipif(&class="cm">#x27;class="st">"__pypy__" in sys.modules')
1142 def test_pyc_vs_pyo(
1143 self,
1144 pytester: Pytester,
1145 monkeypatch: pytest.MonkeyPatch,
1146 ) -> None:
1147 pytester.makepyfile(
1148 class="st">"""
1149 import pytest
1150 def test_optimized():
1151 class="st">"hello"
1152 assert test_optimized.__doc__ is Noneclass="st">"""
1153 )
1154 p = make_numbered_dir(root=Path(pytester.path), prefix=class="st">"runpytest-")
1155 tmp = fclass="st">"--basetemp={p}"
1156 with monkeypatch.context() as mp:
1157 mp.setenv(class="st">"PYTHONOPTIMIZE", class="st">"2")
1158 mp.delenv(class="st">"PYTHONDONTWRITEBYTECODE", raising=False)
1159 mp.delenv(class="st">"PYTHONPYCACHEPREFIX", raising=False)
1160 assert pytester.runpytest_subprocess(tmp).ret == 0
1161 tagged = class="st">"test_pyc_vs_pyo." + PYTEST_TAG
1162 assert tagged + class="st">".pyo" in os.listdir(class="st">"__pycache__")
1163 monkeypatch.delenv(class="st">"PYTHONDONTWRITEBYTECODE", raising=False)
1164 monkeypatch.delenv(class="st">"PYTHONPYCACHEPREFIX", raising=False)
1165 assert pytester.runpytest_subprocess(tmp).ret == 1
1166 assert tagged + class="st">".pyc" in os.listdir(class="st">"__pycache__")
1167
1168 def test_package(self, pytester: Pytester) -> None:
1169 pkg = pytester.path.joinpath(class="st">"pkg")

Callers

nothing calls this directly

Calls 7

make_numbered_dirFunction · 0.90
contextMethod · 0.80
setenvMethod · 0.80
delenvMethod · 0.80
listdirMethod · 0.80
makepyfileMethod · 0.45
runpytest_subprocessMethod · 0.45

Tested by

no test coverage detected