在 PyCharm 中禁用 Pytest [英] Disable Pytest in PyCharm

查看:77
本文介绍了在 PyCharm 中禁用 Pytest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个以test_"开头的文件,PyCharm 会尝试使用 PyTest 运行它.我想正常运行它(作为常规的 Python 脚本).我该怎么做?

If I have a file beginning with "test_", PyCharm tries to run this with PyTest. I want to run it normally (as a regular Python script). How can I do this?

使用解决方案进行正如 A. Romeau 所指出的,有一些方法可以做到这一点:

Edit with Solution: As A. Romeau pointed out, there are ways to do this:

  1. 对于要正常运行的给定测试文件:

  1. For a given test file that you want to run normally:

  • 运行文件...注意它在 py.test 或其他一些测试框架下运行.
  • 点击右上角的下拉框,上面写着py.test in test_something.py".
  • 点击编辑配置".这将打开一个窗口,左侧有Python"和Python 测试"作为选项.您会注意到您位于Python 测试"部分.
  • 复制目标:"字段中的文件路径.
  • 点击左上角的红色-",这将删除该测试配置.
  • 现在,单击绿色的+",选择Python",然后将您复制的文件路径粘贴到脚本:"字段中.
  • 按确定".您的测试文件现在将作为普通脚本运行.

在 pytest 中编辑您的 setup.cfg 文件(使用一些我现在不知道的选项),以便它不会发现"您的测试(我还没有尝试过).

Edit your setup.cfg file in pytest (with some option that I don't know right now) so that it doesn't "discover" your test (I have not tried this).

两种解决方案都不好.1 不方便,因为您需要多次单击并处理您可能希望像这样运行的每个文件.2 不方便,因为它会干扰您从控制台正常运行 pytest.

Neither solution is good. 1 is inconvenient because you need to go through a big mutli-click and process for each file you might want to run like this. 2 is inconvenient because it interferes with you running pytest normally, from console.

JetBrains:为了上帝的爱,请添加一个禁用自动单元测试的选项.这很烦人,因为在尝试跟踪测试中的错误时,pytest/UnitTest 的输出几乎不如常规解释器的输出有用(没有指向失败行的链接,不能轻易地单独运行给定的函数等).

JetBrains: Please for the love of God just add an option to disable automatic unittesting. It is very annoying because the output of pytest/UnitTest is not nearly as helpful as the output of the regular interpreter when trying to track down bugs in tests (no links to the failing line, can't easily run given function alone, etc).

已在此处打开了 PyCharm问题".

A PyCharm "issue" has been opened here.

推荐答案

您可以在运行/编辑配置下为该特定文件创建运行配置,也可以更改 py.test 的测试发现设置,因此文件默认情况下,以 test_* 开头的文件不被视为测试文件.

You can either create a run configuration for that specific file, under Run/Edit Configurations, or you can change the test discovery settings for py.test, so files starting with test_* are not considered test files by default.

更多信息在这里:

http://pytest.org/2.2.4/example/pythoncollection.html

这篇关于在 PyCharm 中禁用 Pytest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆