parent
a24933b0a6
commit
f43fb13179
|
@ -0,0 +1,2 @@
|
|||
The name of the ``.pyc`` files cached by the assertion writer now includes the pytest version
|
||||
to avoid stale caches.
|
|
@ -13,6 +13,7 @@ import types
|
|||
import atomicwrites
|
||||
|
||||
from _pytest._io.saferepr import saferepr
|
||||
from _pytest._version import version
|
||||
from _pytest.assertion import util
|
||||
from _pytest.assertion.util import ( # noqa: F401
|
||||
format_explanation as _format_explanation,
|
||||
|
@ -21,7 +22,7 @@ from _pytest.pathlib import fnmatch_ex
|
|||
from _pytest.pathlib import PurePath
|
||||
|
||||
# pytest caches rewritten pycs in __pycache__.
|
||||
PYTEST_TAG = "{}-PYTEST".format(sys.implementation.cache_tag)
|
||||
PYTEST_TAG = "{}-pytest-{}".format(sys.implementation.cache_tag, version)
|
||||
PYC_EXT = ".py" + (__debug__ and "c" or "o")
|
||||
PYC_TAIL = "." + PYTEST_TAG + PYC_EXT
|
||||
|
||||
|
|
|
@ -780,6 +780,24 @@ def test_rewritten():
|
|||
|
||||
assert testdir.runpytest().ret == 0
|
||||
|
||||
def test_cached_pyc_includes_pytest_version(self, testdir, monkeypatch):
|
||||
"""Avoid stale caches (#1671)"""
|
||||
monkeypatch.delenv("PYTHONDONTWRITEBYTECODE", raising=False)
|
||||
testdir.makepyfile(
|
||||
test_foo="""
|
||||
def test_foo():
|
||||
assert True
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest_subprocess()
|
||||
assert result.ret == 0
|
||||
found_names = glob.glob(
|
||||
"__pycache__/*-pytest-{}.pyc".format(pytest.__version__)
|
||||
)
|
||||
assert found_names, "pyc with expected tag not found in names: {}".format(
|
||||
glob.glob("__pycache__/*.pyc")
|
||||
)
|
||||
|
||||
@pytest.mark.skipif('"__pypy__" in sys.modules')
|
||||
def test_pyc_vs_pyo(self, testdir, monkeypatch):
|
||||
testdir.makepyfile(
|
||||
|
|
Loading…
Reference in New Issue