简体   繁体   English

你如何从pycharm运行nosetest?

[英]How do you run nosetest from pycharm?

How do you execute nosetest from pycharm to run all unit tests? 你如何从pycharm执行nosetest来运行所有的单元测试?

I know that pycharm supports python's unittest and py.test and that they will properly support nosetests in pycharm 1.1 but I was wondering if there was a work around. 我知道pycharm支持python的unittest和py.test,并且他们将在pycharm 1.1中正确支持nosetests,但我想知道是否有解决方法。

In the current version of Pycharm (2.6) there should be a context menu "run Nosetests in ..." on a test file. 在当前版本的Pycharm(2.6)中,应该在测试文件上有一个上下文菜单“在...中运行Nosetests”。 If this is missing, go to file->settings->Project Settings->python integrated tools and ensure the Default Test Runner is Nosetests. 如果缺少这个,请转到file->settings->Project Settings->python integrated tools并确保默认测试运行器是Nosetests。 You do of course need to have Nosetests installed - pycharm will offer this if you do not. 你当然需要安装Nosetests - 如果不这样做,pycharm会提供。

This does have a limitation. 这确实有局限性。 If the file in question does not have a class derived from unittest.TestCase it will not automatically show this. 如果有问题的文件没有派生自unittest.TestCase的类,它将不会自动显示。 If you are using nose.tools or simple assertions it will not automatically offer this. 如果您使用nose.tools或简单的断言,它将不会自动提供此功能。 This is probably a bug. 这可能是一个错误。

If you can live without the graphical test runner, you can simply create a "Python Script" run configuration and run the tests as you run them from the command line. 如果没有图形测试运行器就可以生存,只需创建一个“Python脚本”运行配置,并在从命令行运行测试时运行测试。

The only way to get nose tests working with the graphical test runner, I'm afraid, is to hack on helpers/pycharm/utrunner.py from the PyCharm distribution. 我担心,使用图形测试运行器进行鼻子测试的唯一方法是从PyCharm发行版中破解helpers / pycharm / utrunner.py。

This is easy to accomplish.... 这很容易实现....

I assume you have nose already installed. 我假设你已经安装了鼻子。

And that your project looks like 你的项目看起来像

   \MyProj_Source
      \MyProj
          init.py
          MyProj.py

We need to Create a Tests directory (Yes the name seems to be critical). 我们需要创建一个Tests目录(是的,名称似乎很关键)。 And in that Tests folder we place our nose test file. 在那个Tests文件夹中,我们放置了我们的鼻子测试文件。 So the Directory structure looks like this. 所以Directory结构看起来像这样。

   \MyProj_Source
      \MyProj
          init.py
          MyProj.py
       \Tests
          test_stuff.py

At this point you need to go to 此时你需要去

Preferences-> Tools -> Python Intergrated Tools ** and set **Default Test Runner to be nose 首选项 - >工具 - > Python集成工具**并设置**默认测试运行器为鼻子

You should now be able to 你现在应该能够

Manually 手动

  • Run test_stuff.py using nose 使用nose运行test_stuff.py
  • Enable Auto Testing for the file MyProj.py so after any change the tests are run 为文件MyProj.py启用自动测试,以便在运行测试后进行任何更改

The 2nd way is the best option, but it can be a little time consuming. 第二种方式是最好的选择,但它可能需要一点时间。

Hope that helps. 希望有所帮助。

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

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