0

我正在尝试通过编程调用向pytest发送并行参数,但似乎根本无法识别它们,就像根本没有安装并行时那样,除了我知道存在,因为当我使用直接命令行调用运行py.test时,包括相同的论点,它会找到它并成功运行。

错误:用法:invoke_pytest.py [options] [file_or_dir] [file_or_dir] [...] invoke_pytest.py:错误:无法识别的参数:--workers 1 --tests-per-worker 4

这是我的代码:

import os
import sys
import pytest


pytest_args = [
    "tests/bdd",
    '--rootdir=tests/bdd',
    "--workers 1",
    "--tests-per-worker 4"
    # ...
]
result = pytest.main(pytest_args)
print(f"RESULT {result}")

虽然看起来不相关,但我也在为这个测试套件使用 py.test bdd 和 splinter。

4

1 回答 1

0

弄清楚这是py.test以编程方式解析参数的方式,与并行无关。每个参数的值需要是列表的独立位置!

# ...
pytest_args = [
    "tests/bdd",
    '--rootdir=tests/bdd',
    "--workers", "1",
    "--tests-per-worker", "4", # splitted argument and value
    # ...
]
result = pytest.main(pytest_args)
print(f"RESULT {result}")
于 2019-12-23T15:13:58.557 回答