在 PyCharm IDE 5.0.4 中运行特定的单元测试函数 [英] Run a specific unit test function inside PyCharm IDE 5.0.4

查看:47
本文介绍了在 PyCharm IDE 5.0.4 中运行特定的单元测试函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PyCharm 进行单元测试(使用 unittest),并且能够使其工作:测试运行器很好地显示了测试用例和嵌套测试函数的列表.

I am trying to use PyCharm for unit testing (with unittest), and am able to make it work: the test runner nicely shows the list of test cases and nested test functions.

但是,一旦发现测试,我就找不到任何方法来(重新)运行特定的测试功能:唯一可用的按钮将运行整个测试列表,而右键单击单个测试功能则不会展示为此目的而采取的任何有意义的行动.

However, once the tests have been discovered, I cannot find any way to (re)run a specific test function: the only button available will run the whole list of tests, and right clicking on a single test function doesn't show any meaningful action for this purpose.

您可以想象,当目的是调试单个测试时,可能会花费很长时间不必要的时间.

As you can imagine, it can take a long time unnecessarily when the purpose is to debug a single test.

如何实现?例如,它在 Visual Studio 中是可能的,而且似乎是一个基本功能,所以我想我一定遗漏了一些东西.

How to achieve this? It is possible in Visual Studio for example, and seems like a basic feature so I assume I must be missing something.

推荐答案

检查项目默认测试框架...

Check the default test framework of the project...

您可能习惯于将unittest"作为默认设置.它使我能够将光标放在测试定义上并点击SHIFT-CTRL-R".运行那个测试.

You're perhaps used to 'unittest' being the default. Its enables me to put the cursor on the test definition and hit "SHIFT-CTRL-R" to run that one test.

默认似乎已更改为py.test",它具有不同的行为和键盘快捷键.我在 OSX 上所以 ymmv.

The default seems to have changed to 'py.test' which has different behaviour and keyboard shortcuts. I'm on OSX so ymmv.

在 Linux 上:

文件 ->设置 ->工具 ->Python 集成工具 ->测试/默认测试运行器"

File -> Settings -> Tools -> Python Integrated Tools -> Testing / "Default Test Runner"

在 OSX 上:

首选项 ->工具 ->Python 集成工具 ->默认测试运行程序:"

Preferences -> Tools -> Python Integrated Tools -> "Default test runner:"

这篇关于在 PyCharm IDE 5.0.4 中运行特定的单元测试函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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