pytest不允许在选项中使用引号

2024-06-16 12:41:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用以下代码在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”,这允许somepath包含空格。为什么我打电话时不能做同样的事pytest.main文件在Python代码中?你知道吗


Tags: to代码namepytestoutputpytestmain
1条回答
网友
1楼 · 发布于 2024-06-16 12:41:59

这些报价由shell处理。由于使用pytest.main时没有通过shell调用,因此根本不需要它们。你知道吗

如果你添加它们,你的输入中会有引号,这会导致错误。你知道吗

这两种方法都可以:

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

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

相关问题 更多 >