From e7414aa17f67d05b6ae5a7a66881178936c8b2ac Mon Sep 17 00:00:00 2001 From: Jonas Haag Date: Wed, 31 Aug 2022 19:34:16 +0200 Subject: [PATCH] Run GC in file leak check (#48294) --- pandas/util/_test_decorators.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/util/_test_decorators.py b/pandas/util/_test_decorators.py index 4a4f27f6c7906..5a799cdb89146 100644 --- a/pandas/util/_test_decorators.py +++ b/pandas/util/_test_decorators.py @@ -26,6 +26,7 @@ def test_foo(): from __future__ import annotations from contextlib import contextmanager +import gc import locale from typing import ( Callable, @@ -272,12 +273,13 @@ def file_leak_context() -> Iterator[None]: try: yield finally: + gc.collect() flist2 = proc.open_files() # on some builds open_files includes file position, which we _dont_ # expect to remain unchanged, so we need to compare excluding that flist_ex = [(x.path, x.fd) for x in flist] flist2_ex = [(x.path, x.fd) for x in flist2] - assert flist2_ex == flist_ex, (flist2, flist) + assert set(flist2_ex) <= set(flist_ex), (flist2, flist) conns2 = proc.connections() assert conns2 == conns, (conns2, conns)