pytest不允许选项

时间:2018-02-27 03:25:00

标签: python pytest

我试图使用以下代码在Python代码中调用pytest。代码工作正常。

args = ['test_folder_name', '--junitxml=output.xml', '--ignore=file_to_ignore.py']
ret_code = pytest.main(args)

但是,如果我在选项中的文件路径周围添加双引号,则会引发错误:

args = ['test_folder_name', '--junitxml="output.xml"', '--ignore="file_to_ignore.py"']
ret_code = pytest.main(args)

当我在命令行中调用pytest时,我能够将选项指定为--junitxml =“somepath”,这允许某些路径包含空格。为什么在Python代码中调用pytest.main时我不能做同样的事情?

1 个答案:

答案 0 :(得分:2)

这些引用由shell处理。由于您在使用pytest.main时未通过shell进行通话,因此您根本不需要它们。

如果你添加它们,你的输入中确实会有引号,这可能会导致错误。

其中任何一个都应该有效:

args = [..., '--ignore', 'file to ignore', ...]

args = [..., '--ignore=file to ignore', ...]