我想从python函数调用pytest。我能够使它与os.system
一起工作。我想使用一个子进程来检索pytest输出
cmd = ["pytest", "-s", debug, "DeviceTests/{0}".format(test_name), "--device_id {0}".format(device_address), "--firmware_version {0}".format(firmware_version)]
print(cmd)
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = process.communicate()
print(out)
子进程确实运行,但告诉我有错误。My pytest需要两个CLI选项。运行子流程时,我被告知这两个CLI选项不存在
这是我的命令和错误
Running Test DisioOnBACnetTest
['pytest', '-s', '--disable-pytest-warnings', 'DeviceTests/DisioOnBACnetTest', '--device_id 9101', '--firmware_version 0.1.1']
b''
b'ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]\npytest: error: the following arguments are required: --device_id, --firmware_version\n\n'
如您所见,我正在发送设备id和固件版本,但子进程没有正确地将它们发送到pytest
您需要正确地分隔参数
这:
应该是
相关问题 更多 >
编程相关推荐