summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-07-04 17:38:30 (GMT)
committerGitHub <noreply@github.com>2024-07-04 17:38:30 (GMT)
commit5f660e8e2ca3acfb89ccbdd990f072149b6baa6a (patch)
treee603b8d27c75e983d21d348395e66c067e9d9efb
parentf5c8d67de6c68bea2860d5d96af747c5e95dbf22 (diff)
downloadcpython-5f660e8e2ca3acfb89ccbdd990f072149b6baa6a.zip
cpython-5f660e8e2ca3acfb89ccbdd990f072149b6baa6a.tar.gz
cpython-5f660e8e2ca3acfb89ccbdd990f072149b6baa6a.tar.bz2
gh-121084: Fix test_typing random leaks (#121360)
Clear typing ABC caches when running tests for refleaks (-R option): call _abc_caches_clear() on typing abstract classes and their subclasses.
-rw-r--r--Lib/test/libregrtest/utils.py6
-rw-r--r--Misc/NEWS.d/next/Tests/2024-07-04-15-10-29.gh-issue-121084.qxcd5d.rst3
2 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py
index 0197e50..2a34490 100644
--- a/Lib/test/libregrtest/utils.py
+++ b/Lib/test/libregrtest/utils.py
@@ -264,6 +264,12 @@ def clear_caches():
for f in typing._cleanups:
f()
+ import inspect
+ abs_classes = filter(inspect.isabstract, typing.__dict__.values())
+ for abc in abs_classes:
+ for obj in abc.__subclasses__() + [abc]:
+ obj._abc_caches_clear()
+
try:
fractions = sys.modules['fractions']
except KeyError:
diff --git a/Misc/NEWS.d/next/Tests/2024-07-04-15-10-29.gh-issue-121084.qxcd5d.rst b/Misc/NEWS.d/next/Tests/2024-07-04-15-10-29.gh-issue-121084.qxcd5d.rst
new file mode 100644
index 0000000..b91ea8a
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2024-07-04-15-10-29.gh-issue-121084.qxcd5d.rst
@@ -0,0 +1,3 @@
+Fix test_typing random leaks. Clear typing ABC caches when running tests for
+refleaks (``-R`` option): call ``_abc_caches_clear()`` on typing abstract
+classes and their subclasses. Patch by Victor Stinner.