MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_pyc_vs_pyo

Method test_pyc_vs_pyo

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

Source from the content-addressed store, hash-verified

903
904 @pytest.mark.skipif('"__pypy__" in sys.modules')
905 def test_pyc_vs_pyo(self, pytester: Pytester, monkeypatch) -> None:
906 pytester.makepyfile(
907 """
908 import pytest
909 def test_optimized():
910 "hello"
911 assert test_optimized.__doc__ is None"""
912 )
913 p = make_numbered_dir(root=Path(pytester.path), prefix="runpytest-")
914 tmp = "--basetemp=%s" % p
915 monkeypatch.setenv("PYTHONOPTIMIZE", "2")
916 monkeypatch.delenv("PYTHONDONTWRITEBYTECODE", raising=False)
917 monkeypatch.delenv("PYTHONPYCACHEPREFIX", raising=False)
918 assert pytester.runpytest_subprocess(tmp).ret == 0
919 tagged = "test_pyc_vs_pyo." + PYTEST_TAG
920 assert tagged + ".pyo" in os.listdir("__pycache__")
921 monkeypatch.undo()
922 monkeypatch.delenv("PYTHONDONTWRITEBYTECODE", raising=False)
923 monkeypatch.delenv("PYTHONPYCACHEPREFIX", raising=False)
924 assert pytester.runpytest_subprocess(tmp).ret == 1
925 assert tagged + ".pyc" in os.listdir("__pycache__")
926
927 def test_package(self, pytester: Pytester) -> None:
928 pkg = pytester.path.joinpath("pkg")

Callers

nothing calls this directly

Calls 6

make_numbered_dirFunction · 0.90
setenvMethod · 0.80
delenvMethod · 0.80
undoMethod · 0.80
makepyfileMethod · 0.45
runpytest_subprocessMethod · 0.45

Tested by

no test coverage detected