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

Method test_pyc_vs_pyo

testing/test_assertrewrite.py:1142–1166  ·  view source on GitHub ↗
(
        self,
        pytester: Pytester,
        monkeypatch: pytest.MonkeyPatch,
    )

Source from the content-addressed store, hash-verified

1140
1141 @pytest.mark.skipif('"__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 """
1149 import pytest
1150 def test_optimized():
1151 "hello"
1152 assert test_optimized.__doc__ is None"""
1153 )
1154 p = make_numbered_dir(root=Path(pytester.path), prefix="runpytest-")
1155 tmp = f"--basetemp={p}"
1156 with monkeypatch.context() as mp:
1157 mp.setenv("PYTHONOPTIMIZE", "2")
1158 mp.delenv("PYTHONDONTWRITEBYTECODE", raising=False)
1159 mp.delenv("PYTHONPYCACHEPREFIX", raising=False)
1160 assert pytester.runpytest_subprocess(tmp).ret == 0
1161 tagged = "test_pyc_vs_pyo." + PYTEST_TAG
1162 assert tagged + ".pyo" in os.listdir("__pycache__")
1163 monkeypatch.delenv("PYTHONDONTWRITEBYTECODE", raising=False)
1164 monkeypatch.delenv("PYTHONPYCACHEPREFIX", raising=False)
1165 assert pytester.runpytest_subprocess(tmp).ret == 1
1166 assert tagged + ".pyc" in os.listdir("__pycache__")
1167
1168 def test_package(self, pytester: Pytester) -> None:
1169 pkg = pytester.path.joinpath("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