|
21 | 21 | import pytest |
22 | 22 |
|
23 | 23 | 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 |
25 | 25 | from hypothesis.internal.compat import PYPY |
26 | 26 | from hypothesis.internal.constants_ast import ( |
27 | 27 | Constants, |
@@ -340,12 +340,17 @@ def recording_mkstemp(*args, **kwargs): |
340 | 340 | return fd, path |
341 | 341 |
|
342 | 342 | 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}) |
350 | 355 | assert len(temp_paths) == 1 |
351 | 356 | assert not Path(temp_paths[0]).exists() |
0 commit comments