Sanju Kumar
Sanju Kumar

Reputation: 11

pytest: Run test cases in asynchronous mode for slow tasks

I am using pytest for test automation and some of my tests require validation/assert ( post-process verification) after 10 minutes). I do not want to block my tests for 10 minutes and keep other tests in the queue. Consider a simple example below:

def fun_10_min_delay_verification():
    time.sleep(300)
    return True


def test_1st_test():
    print("Running 1st test")
    assert fun_10_min_delay_verification
    
    
def test_2nd_test_without_delay():
    print("Running 2nd test. I want to start this test ASAP instead of waiting for slow task")
  

I tried to use asyncio to put my delayed assertion but no luck. Any suggestions to run the validation/assertion in async mode to unblock the remaining test execution?

Upvotes: 1

Views: 616

Answers (1)

Gaarv
Gaarv

Reputation: 824

I would advise using pytest-xdist, which is a pytest plugin to runs test in a parallel fashion: https://github.com/pytest-dev/pytest-xdist

Upvotes: 1

Related Questions