house.py
:
class House:
def is_habitable(self):
return True
def is_on_the_ground(self):
return True
One way to do this would be to use the fixture name house
for all test methods (even if it's testing a TreeHouse
), and override its value in each test context:
class TestTreeHouse(TestHouse):
@pytest.fixture
def house(self, tree_house):
return tree_house
def test_groundedness(self, house):
assert not house.is_on_the_ground()
Also note TestTreeHouse
inherits from TestHouse
. Since pytest merely enumerates methods of classes (i.e. there is no "registration" done with, say, a @pytest.test()
decorator), all tests defined in TestHouse
will be discovered in subclasses of it, without any further intervention.