How can I optimize my test cases in pytest when I have to wait for 20 minutes for the results

110 views Asked by At

I apologize if am not clear, kindly let me know I would be glad to provide more information

In my test cases, after executing the test steps, I have to wait for 20 minutes for the results, as the results come after 20 minutes only.

In my automation framework, currently after executing the steps I'm waiting for 20 minutes and then validate the results, but this is leading to a lengthy execution time. I have 70 tests and each test takes around 24 minutes.

I have created my automation framework using selenium + python and pytest, and below is a skeleton of my test case

def test_case():
    test_steps_execution
    wait_for_20_minutes
    validate_results

What I have thought is that I would create a fixture that would be executed once all the test_cases are executed and in this fixture I will first wait for 20 minutes and then validate the results. However in this way the reporting would not be accurate and relevant, as in the reports the pass/failure is determined by the successful execution of the test methods or the test cases. The validations defined in the fixture would not help to mark the test case as pass or fail.

What I'm trying to achieve is to reduce the execution time of all the test cases (currently its taking 70*24 = 1680 minutes = 28 hours).

Apparently, I would like to first execute all the test cases, then wait for the results, then validate the results, and mark the tests as pass or fail based on the validations.

1

There are 1 answers

1
hcchang84 On

I would first use fixture to mock the results as unit tests. These unit tests are used to validate the logic of the executions.

Then, I would use @pytest.mark.slow to mark the slow tests and only run them during integration testing.

I also found some tips that others curated to speed up pytest: https://github.com/zupo/awesome-pytest-speedup.