从命令行运行Pytest时,即使我没有告诉它这样做,它仍然会跳过一些参数化测试。奇怪的是,当使用VSCode中的命令调色板运行时,它不会跳过测试。在
我尝试过单独运行测试和测试文件,并调整命令行选项,但都没有用。大概,我遗漏了一些细微的配置。你能帮忙吗?在
@pytest.mark.parametrize(
"inputs, expec",
helpers.get_samples('inouts/kmp'),
ids=helpers.get_ids('inouts/kmp'))
def test_kmp(capsys, inputs, expec):
"""Sample test
"""
with patch('kmp.sys.stdin', inputs):
kmp.main()
captured = capsys.readouterr()
print(captured.err, file=sys.stderr)
assert captured.out == expec.getvalue()
从命令选项板在VSCode中运行此项目会产生:
platform darwin -- Python 3.7.2, pytest-4.1.0, py-1.7.0, pluggy-0.8.1
rootdir: ... , inifile:
plugins: cov-2.6.1
collected 79 items
test_1.py ........................................ [ 50%]
test_2.py ................................... [ 94%]
test_3.py .... [100%]
generated xml file:
/var/folders/pn/y4jjr_t531g3x3v0s0snqzf40000gn/T/tmp-...
========================== 79 passed in 0.55 seconds ===========================
但是从命令行运行相同的测试会产生:
=============================== test session starts ===============================
platform darwin -- Python 3.7.2, pytest-4.1.0, py-1.7.0, pluggy-0.8.1
rootdir: ... , inifile:
plugins: cov-2.6.1
collected 59 items
test_1.py ssss...................s..... [ 49%]
test_2.py s.......................ss.s [ 96%]
test_3.py s. [100%]
====================== 49 passed, 10 skipped in 0.42 seconds ======================
如何让pytest收集并运行全部76个项目?我没有在VSCode中使用任何特殊选项。我不明白为什么pytest在没有被告知的情况下跳过测试。在
谢谢!在
pytest将自动“跳过”参数化但没有条目的测试。在
最简单的例子是:
和输出
^{pr2}$这里的问题可能是两个执行环境(当前工作目录或其他类似环境)导致数据收集在终端中返回零结果,但在从vscode运行时返回实际结果。我会检查您当前的工作目录和您首先激活的virtualenv,然后从那里进行调试。甚至可以在
get_samples
/get_ids
内部设置一个断点。在相关问题 更多 >
编程相关推荐