我已经将测试框架移至Docker容器中。我的目标之一就是做到这一点,这样我们就可以在每次测试中增加1个容器,然后报告其结果。
我正在使用以下方法[请记住这是一个在制品]:
api_test_runner.py
import subprocess
from api_test_list import single_test_list
for test in single_test_list:
command = subprocess.check_output(['docker', 'run', '-e', 'USER=root', '-e', 'TEST=' + test, 'api_test_container'])
print(command)
这遍历了一系列测试,并为每个测试旋转了一个容器,但是它等待一个容器停止运行,然后再进行下一个测试:
(py3_api_automation) remmac05674:api_automation$ python api_test_runner.py
b'============================= test session starts ==============================\nplatform linux -- Python 3.6.4, pytest-3.2.5, py-1.5.2, pluggy-0.4.0\nrootdir: /app, inifile:\nplugins: xdist-1.20.1, forked-0.2, cloud-2.0.0\ncollected 1 item\n\ntest_1.py .\n\n=========================== 1 passed in 1.81 seconds ===========================\n'
b'============================= test session starts ==============================\nplatform linux -- Python 3.6.4, pytest-3.2.5, py-1.5.2, pluggy-0.4.0\nrootdir: /app, inifile:\nplugins: xdist-1.20.1, forked-0.2, cloud-2.0.0\ncollected 1 item\n\ntest_2.py .
我试图解决的是如何让python在测试列表中运行,并为每个测试启动一个容器,而不等待其他容器完成。
最佳答案
对于那些感兴趣的人,我将脚本更新为使用.Popen
for test in single_test_list:
command = subprocess.Popen(['docker', 'run', '-e', 'USER=root', '-e', 'TEST=' + test, 'api_test_container'])
print(command)