gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 02:06:31 25 4
gpt4 key购买 nike

我尝试使用以下代码在 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 包含空格。为什么在 Python 代码中调用 pytest.main 时不能做同样的事情?

最佳答案

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

如果添加它们,您的输入中实际上会包含引号,这可能会导致错误。

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

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

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

关于python - pytest 不允许在选项中使用引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49000608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com