From 992c5dfe935313e67f8cf23c3ee4a3bc41121296 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Thu, 4 Jul 2024 10:44:56 +0100 Subject: [PATCH] Ensure dynamic classes are garbage collected between tests (#434) --- conftest.py | 9 +++++++++ kr8s/tests/test_api.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/conftest.py b/conftest.py index 8dc84729..05500f50 100644 --- a/conftest.py +++ b/conftest.py @@ -1,5 +1,6 @@ # SPDX-FileCopyrightText: Copyright (c) 2023-2024, Kr8s Developers (See LICENSE for list) # SPDX-License-Identifier: BSD 3-Clause License +import gc import os import time @@ -7,6 +8,14 @@ from pytest_kind.cluster import KindCluster +@pytest.fixture +def ensure_gc(): + """Ensure garbage collection is run before and after the test.""" + gc.collect() + yield + gc.collect() + + @pytest.fixture(scope="session", autouse=True) def k8s_cluster(request) -> KindCluster: image = None diff --git a/kr8s/tests/test_api.py b/kr8s/tests/test_api.py index 578762be..b94f1de7 100644 --- a/kr8s/tests/test_api.py +++ b/kr8s/tests/test_api.py @@ -354,7 +354,7 @@ async def test_nonexisting_resource_type(): "certificatesigningrequests.certificates.k8s.io/v1", ], ) -async def test_dynamic_classes(kind): +async def test_dynamic_classes(kind, ensure_gc): from kr8s.asyncio.objects import get_class api = await kr8s.asyncio.api()