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

Method test_orphaned_pyc_file

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

Source from the content-addressed store, hash-verified

854 assert pytester.runpytest_subprocess().ret == 0
855
856 def test_orphaned_pyc_file(self, pytester: Pytester, monkeypatch) -> None:
857 monkeypatch.delenv("PYTHONPYCACHEPREFIX", raising=False)
858 monkeypatch.setattr(sys, "pycache_prefix", None, raising=False)
859
860 pytester.makepyfile(
861 """
862 import orphan
863 def test_it():
864 assert orphan.value == 17
865 """
866 )
867 pytester.makepyfile(
868 orphan="""
869 value = 17
870 """
871 )
872 py_compile.compile("orphan.py")
873 os.remove("orphan.py")
874
875 # Python 3 puts the .pyc files in a __pycache__ directory, and will
876 # not import from there without source. It will import a .pyc from
877 # the source location though.
878 if not os.path.exists("orphan.pyc"):
879 pycs = glob.glob("__pycache__/orphan.*.pyc")
880 assert len(pycs) == 1
881 os.rename(pycs[0], "orphan.pyc")
882
883 assert pytester.runpytest().ret == 0
884
885 def test_cached_pyc_includes_pytest_version(
886 self, pytester: Pytester, monkeypatch

Callers

nothing calls this directly

Calls 5

delenvMethod · 0.80
setattrMethod · 0.80
compileMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected