toddlers/tests/conftest.py
Nils Philippsen 7fe0937190 Using real objects is considered polite
Previously, ToddlerBase and derived classes were used directly, but none
of the methods is marked as a class or static method. Amazingly enough,
it worked regardless. It's useful to have a constructor, though, so do
things conventionally.

As we can't just monkey-patch the classes then, use the shared `toddler`
fixture which creates the object for the test methods that need it.

Signed-off-by: Nils Philippsen <nils@redhat.com>
2020-07-17 17:39:28 +02:00

17 lines
448 B
Python

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