@pytest individual test decorator to continue assert even after fail?

Viewed 666

To stop the testing process after the first (N) failures:

pytest --maxfail=2 

what I want is

@pytest.some_decorator
def test_one(data):
... #do something
    assert feature1...
    assert feature2...
    assert feature3...

This @pytest.some_decorator should run all assert statements even after the first one fails. It cannot be parameterized as it's a feature of the data.

Is this possible? really doesn't make sense to write multiple tests for tests like this for me.

2 Answers

If you use the normal assert then you're basically wanting to go back inside a function after the function has exited.

You can do that with fuckitpy. See https://github.com/ajalt/fuckitpy#as-a-decorator Maybe there's a way to modify it so it only continues after AssertionErrors and not just any exception.

Split tests with a single assert per test. Use @pytest.mark.xfail() decorator to mark tests you are expecting to fail.

Related