summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2023-12-04 11:23:08 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-12-06 09:26:11 +0100
commitfb9216382a387685e1082ac97caa3feaf3d5fe80 (patch)
tree198e324293a0e9266197aa4db74ea1969680f996
parent1c3614e306e80d5a57c52d36c2a1868e1e5f9ab3 (diff)
Refs #34986 -- Moved garbage_collect() helper to django.test.utils.
-rw-r--r--django/test/utils.py10
-rw-r--r--tests/dispatch/tests.py16
2 files changed, 11 insertions, 15 deletions
diff --git a/django/test/utils.py b/django/test/utils.py
index 08f00f9eb4..ddb85127dc 100644
--- a/django/test/utils.py
+++ b/django/test/utils.py
@@ -1,4 +1,5 @@
import collections
+import gc
import logging
import os
import re
@@ -27,6 +28,7 @@ from django.template import Template
from django.test.signals import template_rendered
from django.urls import get_script_prefix, set_script_prefix
from django.utils.translation import deactivate
+from django.utils.version import PYPY
try:
import jinja2
@@ -38,6 +40,7 @@ __all__ = (
"Approximate",
"ContextList",
"isolate_lru_cache",
+ "garbage_collect",
"get_runner",
"CaptureQueriesContext",
"ignore_warnings",
@@ -982,3 +985,10 @@ def register_lookup(field, *lookups, lookup_name=None):
finally:
for lookup in lookups:
field._unregister_lookup(lookup, lookup_name)
+
+
+def garbage_collect():
+ gc.collect()
+ if PYPY:
+ # Collecting weakreferences can take two collections on PyPy.
+ gc.collect()
diff --git a/tests/dispatch/tests.py b/tests/dispatch/tests.py
index 8e72e626dd..18426d8dd1 100644
--- a/tests/dispatch/tests.py
+++ b/tests/dispatch/tests.py
@@ -1,23 +1,9 @@
-import gc
import weakref
from types import TracebackType
from django.dispatch import Signal, receiver
from django.test import SimpleTestCase
-from django.test.utils import override_settings
-from django.utils.version import PYPY
-
-if PYPY:
-
- def garbage_collect():
- # Collecting weakreferences can take two collections on PyPy.
- gc.collect()
- gc.collect()
-
-else:
-
- def garbage_collect():
- gc.collect()
+from django.test.utils import garbage_collect, override_settings
def receiver_1_arg(val, **kwargs):