Skip to content

Commit

Permalink
Merge pull request #4213 from tybug/remove-gc
Browse files Browse the repository at this point in the history
Remove `gc.collect()` before each test
  • Loading branch information
tybug authored Dec 24, 2024
2 parents a62bc76 + 23f1fae commit 2530e74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 0 additions & 5 deletions hypothesis-python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ def warns_or_raises(request):
return pytest.warns


@pytest.fixture(scope="function", autouse=True)
def _gc_before_each_test():
gc.collect()


@pytest.fixture(scope="function", autouse=True)
def _consistently_increment_time(monkeypatch):
"""Rather than rely on real system time we monkey patch time.time so that
Expand Down
12 changes: 11 additions & 1 deletion hypothesis-python/tests/cover/test_random_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,17 @@ def test_find_does_not_pollute_state():
"ignore:It looks like `register_random` was passed an object that could be garbage collected"
)
def test_evil_prng_registration_nonsense():
gc_collect()
# my guess is that other tests may register randoms that are then marked for
# deletion (but not actually gc'd yet). Therefore, depending on the order tests
# are run, RANDOMS_TO_MANAGE may start with more entries than after a gc. To
# force a clean slate for this test, unconditionally gc.
gc.collect()
# The first test to call deterministic_PRNG registers a new random instance.
# If that's this test, it will throw off our n_registered count in the middle.
# start with a no-op to ensure this registration has occurred.
with deterministic_PRNG(0):
pass

n_registered = len(entropy.RANDOMS_TO_MANAGE)
r1, r2, r3 = random.Random(1), random.Random(2), random.Random(3)
s2 = r2.getstate()
Expand Down

0 comments on commit 2530e74

Please # to comment.