Skip to content

Commit 2530e74

Browse files
authored
Merge pull request #4213 from tybug/remove-gc
Remove `gc.collect()` before each test
2 parents a62bc76 + 23f1fae commit 2530e74

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

hypothesis-python/tests/conftest.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ def warns_or_raises(request):
6868
return pytest.warns
6969

7070

71-
@pytest.fixture(scope="function", autouse=True)
72-
def _gc_before_each_test():
73-
gc.collect()
74-
75-
7671
@pytest.fixture(scope="function", autouse=True)
7772
def _consistently_increment_time(monkeypatch):
7873
"""Rather than rely on real system time we monkey patch time.time so that

hypothesis-python/tests/cover/test_random_module.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,17 @@ def test_find_does_not_pollute_state():
161161
"ignore:It looks like `register_random` was passed an object that could be garbage collected"
162162
)
163163
def test_evil_prng_registration_nonsense():
164-
gc_collect()
164+
# my guess is that other tests may register randoms that are then marked for
165+
# deletion (but not actually gc'd yet). Therefore, depending on the order tests
166+
# are run, RANDOMS_TO_MANAGE may start with more entries than after a gc. To
167+
# force a clean slate for this test, unconditionally gc.
168+
gc.collect()
169+
# The first test to call deterministic_PRNG registers a new random instance.
170+
# If that's this test, it will throw off our n_registered count in the middle.
171+
# start with a no-op to ensure this registration has occurred.
172+
with deterministic_PRNG(0):
173+
pass
174+
165175
n_registered = len(entropy.RANDOMS_TO_MANAGE)
166176
r1, r2, r3 = random.Random(1), random.Random(2), random.Random(3)
167177
s2 = r2.getstate()

0 commit comments

Comments
 (0)