Hello pytest-dev,

I am looking to repeat some of the tests in my test suite, and want to call a 
certain action before each repetition. To be clear, I want to:

1) First, run all the tests marked with repeat, as-is
2) Then, take a specific action, in this case rebooting a device
3) Then, repeat each test marked with repeat
4) Then, repeat steps 2-3 the amount of times specified.

The reason I want to run step #2 before every “repeat” is because step #2 is 
expensive, but needs to be performed before the tests are called. 

So my ideal code might look something like this (not real code):

@pytest.mark.repeat
def test_something()
    check_something == last_result_from_file()

@pytest.mark.repeat
def test_something_else:
    something_else()

def expensive_setup():
    set_up()

Using the above as an example, I want to run test_something and 
test_something_else, then expensive_setup, then the two tests again, then 
expensive_setup, etc. So only one call to expensive_setup for each run 
including test_something() and test_something_else()

What would be a sensible way to go about this?

As an addendum, it is ideal if each test is only reported as -one- test, rather 
than one test being generated for each run. But this last thing I imagine/hope 
I can do in some of the reporting hooks. Ideally, if any one call to the 
functions ends up generating a failure or error, it would be able to fail, and 
abort any attempts at subsequently running (I.e. failures should be final).

However, I’ve found no satisfactory way to do the above. Can anyone provide 
some pointers about a good way to go about this?

In case you’re curious about why the tests need to be repeated, it’s to hunt 
for race conditions, and other failures which may occur sometimes.

Thank you for your time.

Kind Regards,
-- 
Emil Petersen | Software Test Engineer
 <https://www.thalmic.com/>
T: 1-888-777-2546 x692 <>     E: [email protected] 
<mailto:[email protected]>

-- 
----
CONFIDENTIALITY NOTICE:  This communication, and any attachments thereto, 
is confidential and intended solely for use by the recipient(s) named above.


_______________________________________________
pytest-dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-dev

Reply via email to