简体   繁体   English

如何在pycharm中递归运行文件夹中的所有doctests?

[英]How to run all doctests in a folder recursively in pycharm?

Pycharm is great for running all of the doctests per (script / function / class / folder*) but the folder option runs all doctests which are immediately within that folder (not within folders of that folder). Pycharm 非常适合按(脚本/函数/类/文件夹*)运行所有 doctests,但文件夹选项运行该文件夹内(而不是该文件夹的文件夹内)的所有 doctests。

Is there a way to recursively run through some top level folder and run all doctests found?有没有办法递归运行某个顶级文件夹并运行找到的所有 doctests?

This can be done from PyCharm with the help of pytest :这可以在pytest的帮助下从 PyCharm 完成:

  1. If you don't already have it, install pytest by running pip install -U pytest如果你不已经拥有了它,安装pytest运行pip install -U pytest
  2. In PyCharm go to Run --> Edit configurations在 PyCharm 中转到运行-->编辑配置
  3. Add a new configuration by clicking the + button单击+按钮添加新配置
  4. From the pop-up menu, choose Python tests --> py.test从弹出菜单中,选择Python 测试--> py.test
  5. Add --doctest-modules to the Additional Arguments field--doctest-modules添加到附加参数字段
  6. Click OK单击确定

Now running the newly created configuration will discover and run all doctests, even those in subdirectories.现在运行新创建的配置将发现并运行所有 doctests,甚至是子目录中的那些。

See PyCharm's documentation for more configuration options.有关更多配置选项,请参阅PyCharm 的文档

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

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