From 88fd42cdc3a907401c5613b2d8c8ca328cd03fcb Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Tue, 3 Sep 2024 13:10:26 -0700 Subject: [PATCH] fix test interfaces not being disabled --- ...st_interface.py => test_interface_base.py} | 26 ++++++++++--------- tests/test_interface/test_interfaces.py | 12 +++++++++ 2 files changed, 26 insertions(+), 12 deletions(-) rename tests/test_interface/{test_interface.py => test_interface_base.py} (93%) create mode 100644 tests/test_interface/test_interfaces.py diff --git a/tests/test_interface/test_interface.py b/tests/test_interface/test_interface_base.py similarity index 93% rename from tests/test_interface/test_interface.py rename to tests/test_interface/test_interface_base.py index ba69328..baacc60 100644 --- a/tests/test_interface/test_interface.py +++ b/tests/test_interface/test_interface_base.py @@ -1,5 +1,11 @@ -import pytest +""" +Tests for the interface base model, +for tests that should apply to all interfaces, use ``test_interfaces.py`` +""" +import gc + +import pytest import numpy as np from numpydantic.interface import Interface @@ -8,6 +14,7 @@ from numpydantic.interface import Interface @pytest.fixture(scope="module") def interfaces(): """Define test interfaces in this module, and delete afterwards""" + interfaces_enabled = True class Interface1(Interface): input_types = (list,) @@ -24,7 +31,7 @@ def interfaces(): @classmethod def enabled(cls) -> bool: - return True + return interfaces_enabled Interface2 = type("Interface2", Interface1.__bases__, dict(Interface1.__dict__)) Interface2.checked = False @@ -44,7 +51,7 @@ def interfaces(): @classmethod def enabled(cls) -> bool: - return True + return interfaces_enabled class Interfaces: interface1 = Interface1 @@ -55,9 +62,13 @@ def interfaces(): yield Interfaces # Interface.__subclasses__().remove(Interface1) # Interface.__subclasses__().remove(Interface2) + del Interfaces del Interface1 del Interface2 del Interface3 + del Interface4 + interfaces_enabled = False + gc.collect() def test_interface_match_error(interfaces): @@ -151,12 +162,3 @@ def test_interface_recursive(interfaces): assert issubclass(interfaces.interface3, interfaces.interface1) assert issubclass(interfaces.interface1, Interface) assert interfaces.interface4 in ifaces - - -def test_interface_revalidate(all_interfaces): - """ - An interface should revalidate with the output of its initial validation - - See: https://github.com/p2p-ld/numpydantic/pull/14 - """ - _ = type(all_interfaces)(array=all_interfaces.array) diff --git a/tests/test_interface/test_interfaces.py b/tests/test_interface/test_interfaces.py new file mode 100644 index 0000000..36308c9 --- /dev/null +++ b/tests/test_interface/test_interfaces.py @@ -0,0 +1,12 @@ +""" +Tests that should be applied to all interfaces +""" + + +def test_interface_revalidate(all_interfaces): + """ + An interface should revalidate with the output of its initial validation + + See: https://github.com/p2p-ld/numpydantic/pull/14 + """ + _ = type(all_interfaces)(array=all_interfaces.array)