我尝试使用一个自定义输入参数--trustkey_jks来运行pytest。在
像这样跑:
sh-4.2$ pytest -m test_e2e.py --trustkey_jks somekey
ERROR: usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: argument --trustkey_jks: expected one argument
也尝试过这样:
^{pr2}$可以省略文件名以让pytest收集任何测试:
sh-4.2$ py.test --trustkey_jks somekey
ERROR: usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: argument --trustkey_jks: expected one argument
我的conftest.py(与测试水平相同:
# conftest.py
def pytest_addoption(parser):
parser.addoption("--trustkey_jks", action="store")
@pytest.fixture()
def trustkey_jks(request):
return request.config.getoption("--trustkey_jks")
据我所知,pytest无法解析输入参数。 谢谢你的帮助。在
注意:以上是发生在一个Openshift吊舱内,不确定是否重要。在
我能在我的结尾重现你的问题,也找到了根源-因为。那个问题是conftest.py的pytest功能。在
你需要添加所有选项.addparser在你的conftest.py因为默认情况下它将由pytest从conftest加载。如果您想在python文件中添加命令行参数(不创建conftest.py),使用以下内容片段:-在
另外,请参阅conftest.py特点:https://docs.pytest.org/en/latest/example/simple.html。在
相关问题 更多 >
编程相关推荐