11import inspect
2+ from typing import Any
23
3- from unittest import TestCase
44import _models # type: ignore # did not set types for this
55import tableauserverclient as TSC
66
7- from typing import Any
7+ import pytest
88
99
1010# ensure that all models that don't need parameters can be instantiated
@@ -31,21 +31,16 @@ def instantiate_class(name: str, obj: Any):
3131 print (f"Class '{ name } ' does not have a constructor (__init__ method)." )
3232
3333
34- class TestAllModels (TestCase ):
35- # not all models have __repr__ yet: see above list
36- def test_repr_is_implemented (self ):
37- m = _models .get_defined_models ()
38- for model in m :
39- with self .subTest (model .__name__ , model = model ):
40- print (model .__name__ , type (model .__repr__ ).__name__ )
41- self .assertEqual (type (model .__repr__ ).__name__ , "function" )
34+ def is_concrete (obj : Any ):
35+ return inspect .isclass (obj ) and not inspect .isabstract (obj )
4236
43- # 2 - Iterate through the objects in the module
44- def test_by_reflection (self ):
45- for class_name , obj in inspect .getmembers (TSC , is_concrete ):
46- with self .subTest (class_name , obj = obj ):
47- instantiate_class (class_name , obj )
4837
38+ @pytest .mark .parametrize ("class_name, obj" , inspect .getmembers (TSC , is_concrete ))
39+ def test_by_reflection (class_name , obj ):
40+ instantiate_class (class_name , obj )
4941
50- def is_concrete (obj : Any ):
51- return inspect .isclass (obj ) and not inspect .isabstract (obj )
42+
43+ @pytest .mark .parametrize ("model" , _models .get_defined_models ())
44+ def test_repr_is_implemented (model ):
45+ print (model .__name__ , type (model .__repr__ ).__name__ )
46+ assert type (model .__repr__ ).__name__ == "function"
0 commit comments