Home > Enterprise >  How to run pytest from a python script subprocess
How to run pytest from a python script subprocess

Time:03-12

I need to run pytest test_start.py and keep running the program.

My cod:

import subprocess

subprocess.run(['pytest', r'C:\Python\test_start.py'], shell=True)
print('hello')

But when I run the script, pytest starts executing and print waits for it to finish. How can I run py test and go ahead to execute the script?

UPD: When i used subprocess.Popen - I see that print has been executed, but I don't see the execution of pytest

CodePudding user response:

subprocess.run specifically waits for the process to finish. If you don't want to wait, use subprocess.Popen

CodePudding user response:

I solved this problem by simply adding time.sleep(5) after subprocess

subprocess.Popen(['pytest', r'E:\Parser\Python\test_start.py'], shell=True)
time.sleep(5)
print('hello')

Apparently pytest just didn't have time to start)

  • Related