根据 pytest 文档,我应该能够使用 \'and\' 表达式,如下所示:
\n\npytest -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\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试的是这个表达式:
\n\npytest -v test_file.py -k \xe2\x80\x9cTestTest and not test_bad\xe2\x80\x9d\nRun Code Online (Sandbox Code Playgroud)\n\n我得到的错误是:
\n\nERROR: file not found: and\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试过的其他变体也以同样的失败告终:
\n\npytest -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\nRun Code Online (Sandbox Code Playgroud)\n\n最后我的 pytest 版本是:3.0.3
你的\xe2\x80\x9cand\xe2\x80\x9d是一些奇怪的印刷引号,而不是用于防止终端参数"分割的 ascii 引号,这意味着你的 pytest 实际上有四个参数:\xe2\x80\x9cTestTest、and和。nottest_bad\xe2\x80\x9d
当我使用时,你的例子对我来说效果很好"。