So I'm attempting to implement something similar to how unittesting frameworks do the following thing:
class BaseTest(T.TestCase):
# Disables this test from being run
__test__ = False
def test_foo(self): pass
# However this test is picked up because it doesn't directly have __test__ set
class InheritingTest(BaseTest): pass
A thing I find peculiar:
# >> InheritingTest.__test__
# False
Which would indicate to me that it isn't using a metaclass to set __test__
to True
on construction of the type.
I tried grepping through the python library find . -name "*.py" | xargs grep '__test__'
but did not seem to find anything related to this.
My "guess" approach at solving this problem is to do the following:
def is_class_tested(cls):
return cls.__dict__.get('__test__', True)
However this feels fragile to me... Is there a cleaner / nicer way to do this that works in all cases? Is there ever a chance that a class will not have a __dict__
property?