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()