简体   繁体   中英

How to run pytest from a python script subprocess

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

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM