[Python] pytest_django model class attribute not filled for __init_subclass__

Discussão em 'Python' iniciado por Stack, Fevereiro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I have a specific problem.

    class A:
    SOME_ATTR: int

    def __init_subclass__(cls, **kwargs):
    super().__init_subclass__(**kwargs)
    attr = getattr(cls, "SOME_ATTR", None)
    if not attr:
    raise TypeError(f"Class '{cls.__name__}' must define 'SOME_ATTR'")

    classB(models.Model, A):
    SOME_ATTR = 0


    In this case everything works as expected but pytest tests. pytest_django creates: cls = <class 'fake.B'> which has no attribute 'SOME_ATTR' Is there any option to enforce it?

    I'v tried to add a session scope autouse fixture but it didn't work as it happens before it.

    Continue reading...

Compartilhe esta Página