diff --git a/test/models/test_repr.py b/test/models/test_repr.py index 92d11978f..0f6057f4f 100644 --- a/test/models/test_repr.py +++ b/test/models/test_repr.py @@ -1,10 +1,10 @@ import inspect +from typing import Any -from unittest import TestCase import _models # type: ignore # did not set types for this import tableauserverclient as TSC -from typing import Any +import pytest # ensure that all models that don't need parameters can be instantiated @@ -31,21 +31,16 @@ def instantiate_class(name: str, obj: Any): print(f"Class '{name}' does not have a constructor (__init__ method).") -class TestAllModels(TestCase): - # not all models have __repr__ yet: see above list - def test_repr_is_implemented(self): - m = _models.get_defined_models() - for model in m: - with self.subTest(model.__name__, model=model): - print(model.__name__, type(model.__repr__).__name__) - self.assertEqual(type(model.__repr__).__name__, "function") +def is_concrete(obj: Any): + return inspect.isclass(obj) and not inspect.isabstract(obj) - # 2 - Iterate through the objects in the module - def test_by_reflection(self): - for class_name, obj in inspect.getmembers(TSC, is_concrete): - with self.subTest(class_name, obj=obj): - instantiate_class(class_name, obj) +@pytest.mark.parametrize("class_name, obj", inspect.getmembers(TSC, is_concrete)) +def test_by_reflection(class_name, obj): + instantiate_class(class_name, obj) -def is_concrete(obj: Any): - return inspect.isclass(obj) and not inspect.isabstract(obj) + +@pytest.mark.parametrize("model", _models.get_defined_models()) +def test_repr_is_implemented(model): + print(model.__name__, type(model.__repr__).__name__) + assert type(model.__repr__).__name__ == "function"