8
8
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
9
9
# obtain one at https://mozilla.org/MPL/2.0/.
10
10
11
- from pathlib import Path
12
- import warnings
13
-
11
+ import _hypothesis_globals
14
12
import pytest
15
13
16
- import _hypothesis_globals
17
- from hypothesis import configuration as fs
14
+ from hypothesis import configuration as fs , strategies as st
18
15
from hypothesis .errors import HypothesisSideeffectWarning
19
- from hypothesis import strategies as st
20
16
21
17
IN_INITIALIZATION_ATTR = "in_initialization"
22
18
30
26
31
27
32
28
@pytest .fixture
33
- def extend_initialization (monkeypatch ):
29
+ def _extend_initialization (monkeypatch ):
34
30
assert getattr (_hypothesis_globals , IN_INITIALIZATION_ATTR ) == 0
35
31
monkeypatch .setattr (_hypothesis_globals , IN_INITIALIZATION_ATTR , 1 )
36
32
fs .notice_initialization_restarted (warn = False )
@@ -40,19 +36,19 @@ def extend_initialization(monkeypatch):
40
36
@pytest .mark .parametrize (
41
37
"sideeffect, warning_text" ,
42
38
[
43
- (lambda : st .integers ( ).wrapped_strategy , "lazy evaluation" ),
39
+ (lambda : st .builds ( lambda : None ).wrapped_strategy , "lazy evaluation" ), # guaranteed not cached
44
40
(lambda : st .deferred (st .integers ).wrapped_strategy , "deferred evaluation" ),
45
41
(fs .storage_directory , "accessing storage" ),
46
42
],
47
43
)
48
- def test_sideeffect_warning (sideeffect , warning_text , extend_initialization ):
44
+ def test_sideeffect_warning (sideeffect , warning_text , _extend_initialization ):
49
45
with pytest .warns (HypothesisSideeffectWarning , match = warning_text ):
50
46
sideeffect ()
51
47
52
48
53
- def test_sideeffect_delayed_warning (monkeypatch , extend_initialization ):
49
+ def test_sideeffect_delayed_warning (monkeypatch , _extend_initialization ):
54
50
what = "synthetic side-effect"
55
- # extend_initialization ensures we start at known clean slate (no delayed warnings).
51
+ # _extend_initialization ensures we start at known clean slate (no delayed warnings).
56
52
# Then: stop initialization, check a side-effect operation, and restart it.
57
53
monkeypatch .setattr (_hypothesis_globals , IN_INITIALIZATION_ATTR , 0 )
58
54
fs .check_sideeffect_during_initialization (what )
0 commit comments