Skip to content

Commit e57fd12

Browse files
pschanelyclaude
andcommitted
Isolate the constants cache test from existing cache files
The cover suite can run more than once against the same .hypothesis directory (e.g. check-abi3t runs 3.15 and 3.15t), so the cache file could already exist and skip the write under test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c8981a0 commit e57fd12

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

‎hypothesis/tests/cover/test_constants_ast.py‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import pytest
2222

2323
from hypothesis import example, given, note, settings, strategies as st
24-
from hypothesis.configuration import storage_directory
24+
from hypothesis.configuration import set_hypothesis_home_dir, storage_directory
2525
from hypothesis.internal.compat import PYPY
2626
from hypothesis.internal.constants_ast import (
2727
Constants,
@@ -340,12 +340,17 @@ def recording_mkstemp(*args, **kwargs):
340340
return fd, path
341341

342342
monkeypatch.setattr(tempfile, "mkstemp", recording_mkstemp)
343-
assert constants_from_module(module) == Constants(integers={constant})
344-
345-
source_hash = hashlib.sha1(p.read_bytes()).hexdigest()[:16]
346-
cache_p = storage_directory("constants").path / source_hash
347-
assert _constants_from_source(cache_p.read_bytes(), limit=True) == Constants(
348-
integers={constant}
349-
)
343+
# use an empty storage directory, so the cache file can't already exist
344+
previous_home_dir = storage_directory().path
345+
set_hypothesis_home_dir(tmp_path / "hypothesis_home")
346+
try:
347+
assert constants_from_module(module) == Constants(integers={constant})
348+
source_hash = hashlib.sha1(p.read_bytes()).hexdigest()[:16]
349+
cache_p = storage_directory("constants").path / source_hash
350+
cached = _constants_from_source(cache_p.read_bytes(), limit=True)
351+
finally:
352+
set_hypothesis_home_dir(previous_home_dir)
353+
354+
assert cached == Constants(integers={constant})
350355
assert len(temp_paths) == 1
351356
assert not Path(temp_paths[0]).exists()

0 commit comments

Comments
 (0)