pytest 不允许在选项中使用引号
pytest doesn't allow quotes in options
我正在尝试使用以下代码在 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。该代码工作正常。
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', ...]