pytest -k 带有 and 语句标志

sti*_*ing 3 pytest

根据 pytest 文档,我应该能够使用 \'and\' 表达式,如下所示:

\n\n
pytest -k stringexpr # only run tests with names that match the\n                     # "string expression", e.g. "MyClass and not method"\n                     # will select TestMyClass.test_something\n                     # but not TestMyClass.test_method_simple\n
Run Code Online (Sandbox Code Playgroud)\n\n

我尝试的是这个表达式:

\n\n
pytest -v test_file.py -k \xe2\x80\x9cTestTest and not test_bad\xe2\x80\x9d\n
Run Code Online (Sandbox Code Playgroud)\n\n

我得到的错误是:

\n\n
ERROR: file not found: and\n
Run Code Online (Sandbox Code Playgroud)\n\n

我尝试过的其他变体也以同样的失败告终:

\n\n
pytest -v -k \xe2\x80\x9cTestTest and not test_bad\xe2\x80\x9d\npytest -v -k \xe2\x80\x9cTestTest and not test_bad\xe2\x80\x9d test_file.py\n
Run Code Online (Sandbox Code Playgroud)\n\n

最后我的 pytest 版本是:3.0.3

\n

The*_*ler 6

你的\xe2\x80\x9cand\xe2\x80\x9d是一些奇怪的印刷引号,而不是用于防止终端参数"分割的 ascii 引号,这意味着你的 pytest 实际上有四个参数:\xe2\x80\x9cTestTestand和。nottest_bad\xe2\x80\x9d

\n\n

当我使用时,你的例子对我来说效果很好"

\n