[Python] Configurable class fixture for pytest depending on which tests are going to be...

Discussão em 'Python' iniciado por Stack, Setembro 3, 2025.

  1. Stack

    Stack Membro Participativo

    In a test class I have a number of tests, they all share a setup/teardown fixture by using a class scoped fixture that is basically:

    # common_setup...

    setup_needed_for_test1()
    setup_needed_for_test2()
    ...
    setup_needed_for_testN()

    yield

    # common_teardown...


    The reason for this is that the setup functions complete very quickly by themselves, but kick off work in the server. Each test waits for the work to complete, and they can take a very long time if run in series. By doing it this way things can be a bit more parallelized.

    The problem is, if I only want to run test1 (say via IDE), the setup/teardown fixture still runs the setup for each test.

    I have two questions:


    1. Is there a way to instrument this fixture based on what tests pytest will be running to only call the setups for those functions?


    2. Or, is there a better way to accomplish what I am trying to accomplish?

    Continue reading...

Compartilhe esta Página