Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you run nosetest from pycharm?

How do you execute nosetest from pycharm to run all unit tests?

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.

like image 661
Nick Sonneveld Avatar asked Oct 14 '10 05:10

Nick Sonneveld


People also ask

Which command is used to run nose tests?

nose can be integrated with DocTest by using with-doctest option in athe bove command line. The result will be true if the test run is successful, or false if it fails or raises an uncaught exception. nose supports fixtures (setup and teardown methods) at the package, module, class, and test level.


3 Answers

In the current version of Pycharm (2.6) there should be a context menu "run Nosetests in ..." on a test file. If this is missing, go to file->settings->Project Settings->python integrated tools and ensure the Default Test Runner is Nosetests. You do of course need to have Nosetests installed - pycharm will offer this if you do not.

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. If you are using nose.tools or simple assertions it will not automatically offer this. This is probably a bug.

like image 134
Danny Staple Avatar answered Oct 24 '22 10:10

Danny Staple


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.

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.

like image 32
yole Avatar answered Oct 24 '22 11:10

yole


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). And in that Tests folder we place our nose test file. So the Directory structure looks like this.

   \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

You should now be able to

Manually

  • Run test_stuff.py using nose
  • Enable Auto Testing for the file MyProj.py so after any change the tests are run

The 2nd way is the best option, but it can be a little time consuming.

Hope that helps.

like image 2
Tim Seed Avatar answered Oct 24 '22 09:10

Tim Seed