I have a lot of similar groups of tests and would like to make a more general parent test collection as a class. In the class, I'd like to group the fixtures as well, but in some child classes I need to alter the fixtures slightly.
Something like TestCase2 below:
import pytest
class ParentCheckClass:
"""this parent test class is never run, it's a template"""
@pytest.fixture
def settings(self):
return {"a": 1, "b": 2}
def test_for_a(self, settings):
assert "a" in settings
def test_for_c(self, settings):
assert "c" in settings
class TestCase1(ParentCheckClass):
@pytest.fixture
def settings(self):
return {"c": 3}
class TestCase2(ParentCheckClass):
@pytest.fixture
def settings(self):
return super().settings().update({"c": 3})
TestCase1 works as I expect: test_for_a
fails.
TestCase2 throws the error:
Fixture "settings" called directly. Fixtures are not meant to be called directly,
but are created automatically when test functions request them as parameters.
Is there any way to do what I want?