如何在测试文件上告诉 PyCharm 到 运行 pytest 而不是 doctests

how to tell PyCharm to run pytest on test files not doctests

在模块的测试套件中,一些 test_foo.py 文件的文档字符串中包含包含文档测试模式的辅助函数。这导致 PyCharm 在该文件中选择一个函数并尝试通过上下文菜单调试该函数时提供 Debug 'Doctests in test_foo'。该函数是在任何实际 test_...() 函数之前还是在文件末尾都没有关系,仅存在带有 doctests 模式的单个文档字符串就会导致 PyCharm 表现出这种行为。

例如,如果我只是将所有 >>> ... 更改为 />>> ...(以削弱 doctests 搜索),那么测试文件的行为与预期的一样:功能上的上下文菜单提供Debug 'pytest for test_foo.test_function'.

如果两者都可行,有没有办法告诉 PyCharm 优先 pytest 而不是 doctests

尝试 运行 -> 运行 ... 菜单选项。弹出窗口应该有多个选择,包括 pytest

请在PyCharm的问题跟踪器https://youtrack.jetbrains.com/issue/PY-35985

中为相应的工单投票