import pytest @pytest.fixture def toddler(request, monkeypatch): """Fixture creating a toddler for a class testing it The test class must set the toddler class in its `toddler_cls` attribute. """ test_cls = request.cls if not hasattr(test_cls, "toddler_cls"): raise RuntimeError(f"{test_cls} needs to set `toddler_cls`") toddler_cls = test_cls.toddler_cls toddler_obj = toddler_cls() return toddler_obj