How do you run nosetest from pycharm?
Asked Answered
B

3

30

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.

Belenbelesprit answered 14/10, 2010 at 5:45 Comment(1)
Nose tests works from now in Pycharm.Marinelli
B
41

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.

Buonaparte answered 13/11, 2012 at 10:39 Comment(3)
This does have a limitation. If the file in question has not imported unittest (it uses nose.tools, or mock assert or something else), then pycharm will not automatically offer this run option.Buonaparte
In PyCharm 4 you will find this option in File --> Settings --> Tools --> Python Integrated Tools. Default test runner = "Nosetests".Gunsmith
Zymotik - that initial "file" is in all versionsBuonaparte
P
2

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.

Prichard answered 14/10, 2010 at 9:53 Comment(1)
Hopefully when pycharm 1.1 is released you can edit your answer. :)Belenbelesprit
M
2

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.

Marinelli answered 10/5, 2018 at 6:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.