[Python] How to mark a unit test with `pytest` as a success if a single assertion among many...

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

  1. Stack

    Stack Membro Participativo

    Consider the following code:

    def test():
    output = my_func()
    assert output == "option 1"
    assert output == "option 2"


    I only care that one of the assertions does not fail. I know I could collect the comparisons into a list and assert the result of any(), but in this way I lose all the diffing/output from pytest. What's the best practice in this case?

    Continue reading...

Compartilhe esta Página