简体   繁体   English

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

[英]how to tell PyCharm to run pytest on test files not doctests

In the test suite of a module, some test_foo.py files have helper functions containing doctests patterns in their docstrings.在模块的测试套件中,一些test_foo.py文件具有辅助函数,其文档字符串中包含 doctests 模式。 This causes PyCharm to offer Debug 'Doctests in test_foo' when selecting a function inside that file and trying via context-menu to debug just that function.这会导致 PyCharm 在该文件中选择 function 并尝试通过上下文菜单仅调试该 ZC1C425268E68385D1AB5074C17ZA9 时提供Debug 'Doctests in test_foo' It doesn't matter whether that function is before any actual test_...() function or at the end of the file, the mere presence of a single docstring with a doctests pattern causes PyCharm to exhibit this behavior. function 是在任何实际test_...() function 之前还是在文件末尾都没有关系,仅仅存在带有 doctests 模式的单个文档字符串就会导致 Z4149CE0530A909A18F62 表现出行为。

If I just change all the >>>... into />>>... for example (to cripple the doctests search), then the behavior is as expected for a test file: context-menu on a function offers Debug 'pytest for test_foo.test_function' .如果我只是将所有>>>...更改为/>>>...例如(以削弱 doctests 搜索),那么测试文件的行为与预期的一样: function 上的上下文菜单提供Debug 'pytest for test_foo.test_function'

Is there a way to tell PyCharm to prioritize pytest over doctests if both are feasible?如果两者都可行,有没有办法告诉 PyCharm 将pytest优先于doctests

Try Run -> Run... menu option.尝试运行 -> 运行...菜单选项。 The popup should have multiple choices including pytest弹出窗口应该有多个选择,包括 pytest

在此处输入图像描述

Please vote for the corresponding ticket in PyCharm's issue tracker https://youtrack.jetbrains.com/issue/PY-35985请在 PyCharm 的问题跟踪器https://youtrack.jetbrains.com/issue/PY-35985中投票给相应的票

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM