I agree with the other answer that in your case, using pytest.mark.parametrize is the best approach. However, for completeness, you are able to clear captured output with the capsys fixture.
Example:
def logic(letter): print("Handling letter", letter) return letter.isupper() def test_foo(): letters = ["A", "b", "c"] for letter in letters: assert logic(letter)
The test will fail at "b" and print:
----------------------------- Captured stdout call ----------------------------- Handling letter A Handling letter b
To prevent the output from (successfully) handling "A", we can add capsys to the arguments and use capsys.readouterr to clear the buffer in between:
def test_foo(capsys): letters = ["A", "b", "c"] for letter in letters: assert logic(letter) capsys.readouterr()
Now, the tests still fail at "b", but only print:
----------------------------- Captured stdout call ----------------------------- Handling letter b
pytestwill finish test execution after first failed assertion so you will see only one error log.logiccalls because they are in the same scope as failed assertlogiccalls... It wasn't clear. Glad that you got an answer :)