File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change
1
+ The name of the ``.pyc `` files cached by the assertion writer now includes the pytest version
2
+ to avoid stale caches.
Original file line number Diff line number Diff line change 13
13
import atomicwrites
14
14
15
15
from _pytest ._io .saferepr import saferepr
16
+ from _pytest ._version import version
16
17
from _pytest .assertion import util
17
18
from _pytest .assertion .util import ( # noqa: F401
18
19
format_explanation as _format_explanation ,
21
22
from _pytest .pathlib import PurePath
22
23
23
24
# pytest caches rewritten pycs in __pycache__.
24
- PYTEST_TAG = "{}-PYTEST " .format (sys .implementation .cache_tag )
25
+ PYTEST_TAG = "{}-pytest-{} " .format (sys .implementation .cache_tag , version )
25
26
PYC_EXT = ".py" + (__debug__ and "c" or "o" )
26
27
PYC_TAIL = "." + PYTEST_TAG + PYC_EXT
27
28
Original file line number Diff line number Diff line change @@ -780,6 +780,24 @@ def test_it():
780
780
781
781
assert testdir .runpytest ().ret == 0
782
782
783
+ def test_cached_pyc_includes_pytest_version (self , testdir , monkeypatch ):
784
+ """Avoid stale caches (#1671)"""
785
+ monkeypatch .delenv ("PYTHONDONTWRITEBYTECODE" , raising = False )
786
+ testdir .makepyfile (
787
+ test_foo = """
788
+ def test_foo():
789
+ assert True
790
+ """
791
+ )
792
+ result = testdir .runpytest_subprocess ()
793
+ assert result .ret == 0
794
+ found_names = glob .glob (
795
+ "__pycache__/*-pytest-{}.pyc" .format (pytest .__version__ )
796
+ )
797
+ assert found_names , "pyc with expected tag not found in names: {}" .format (
798
+ glob .glob ("__pycache__/*.pyc" )
799
+ )
800
+
783
801
@pytest .mark .skipif ('"__pypy__" in sys.modules' )
784
802
def test_pyc_vs_pyo (self , testdir , monkeypatch ):
785
803
testdir .makepyfile (
You can’t perform that action at this time.
0 commit comments