[Python] How to override non-local fixtures in Pytest?

Discussão em 'Python' iniciado por Stack, Maio 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to access a fixture located in a library through a class that is not referentiated @ all.py. This fixture is defined like:

    # module root library.<>._generic
    class ReferenceFileTest:
    @pytest.fixture
    def reference_folder_name(self) -> str:
    return "ref"


    And what basicly this does is append the name ref to the created folder using --regenerate. But I would like this name to be an absolute path instead, precising it myself. In fact, what I thought doing was using the overriding capabilities of pytest through conftest.py, instantiating the fixture as:

    # conftest.py
    @pytest.fixture(scope="session")
    def reference_folder_name() -> str:
    return "reference"


    However, this doesn't work, and neither does requesting the "mother" fixture, nor redefining the class or whatsoever. The fixture reference_folder_name exists, and it is possible to see it using --fixtures when running pytest. I would need to precise this and change its name as I intend on relocating all files in a different folder which then I can use as well for testing (as my comparing functions instantiate this class as well). Any help would be appreciated.

    Continue reading...

Compartilhe esta Página