pytest-repeat icon indicating copy to clipboard operation
pytest-repeat copied to clipboard

Squash repeated tests into one test result

Open finefoot opened this issue 5 years ago • 6 comments

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?

finefoot avatar May 31 '19 23:05 finefoot

currenly there is not

RonnyPfannschmidt avatar Jun 01 '19 05:06 RonnyPfannschmidt

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?

finefoot avatar Jun 01 '19 08:06 finefoot

I'm not aware of plans

RonnyPfannschmidt avatar Jun 01 '19 15:06 RonnyPfannschmidt

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.

blueyed avatar Jun 01 '19 20:06 blueyed

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

RonnyPfannschmidt avatar Jun 02 '19 06:06 RonnyPfannschmidt

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

RonnyPfannschmidt avatar Jun 19 '19 14:06 RonnyPfannschmidt

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".

okken avatar Jan 21 '24 15:01 okken