pytest-dev / pytest-repeat

pytest plugin for repeating test execution
https://pypi.python.org/pypi/pytest-repeat/
Other
169 stars 27 forks source link

Squash repeated tests into one test result #38

Closed finefoot closed 7 months ago

finefoot commented 5 years ago

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?

RonnyPfannschmidt commented 5 years ago

currenly there is not

finefoot commented 5 years ago

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?

RonnyPfannschmidt commented 5 years ago

I'm not aware of plans

blueyed commented 5 years ago

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.

RonnyPfannschmidt commented 5 years ago

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 commented 5 years ago

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

okken commented 7 months ago

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