pytest-repeat
pytest-repeat copied to clipboard
Squash repeated tests into one test result
Is there a way to "squash" repeated tests into one test result?
@pytest.mark.repeat(5)
def test_example():
assert random.choice([True, False])
This gives me 5 results.
Is there something like @pytest.mark.repeat(5, squash=True)
which effectively does:
def test_example():
for _ in range(5):
assert random.choice([True, False])
Yet, without modifying test_example
by inserting a for
loop?
currenly there is not
Hey @RonnyPfannschmidt thanks for getting back to me. I think it would be a really useful feature in some cases. You say "currently not", so is it something that's planned for future releases?
I'm not aware of plans
I assume it's not trivial, but you could certainly give it a try -a good way to learn about pytest's internals I guess.
Remembered me about https://github.com/pytest-dev/pytest-repeat/issues/15 - i.e. it could require some changes to pytest-repeat's (or pytest's) core.
i suspect it will require multiple major refactors to do this correct, there may be a more hackish solution to it as well, but i wouldn't touch that
using subtests, there may be a way to hackishly archvie this
the cost would be keeping fixtures set up, one would bascially instead of normally calling/parameterizing the test, use the subtest system to generate the calls
that way there is 5 subtest results, but only one test result
I think this feature is very much a different behavior and even if implemented, would not work with scope other than function, so I'm recommending closing this as "won't implement".