Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Python nose tests with a different version of Python

We have CentOS with the ancient Python 2.4 interpreter.

But we would like to write out tests with a newer 2.5/2.6 syntax.

Assuming we have a second Python interpreter installed (e.g. python2.6) is there any way to run the 'nosetests' shell command and tell it to use a specific python interpreter instead of the default one?

like image 636
Jacek Furmankiewicz Avatar asked Dec 16 '10 16:12

Jacek Furmankiewicz


People also ask

How do you import a nose in python?

The Nose package can be imported by using import nose in the code, however this step is optional. If you are making use of specific modules in Nose, the same has to be imported using import Nose. <module_name> in the code.

Can nose run Pytest?

pytest has basic support for running tests written for nose.


2 Answers

The nosetests file is in Python, so it should just be a matter of running it in your new version. Find where the file is:

which nosetests

Then:

python2.6 /usr/bin/nosetests

Adjusting the name and path to match your system. I've not tested, but that should work.

like image 78
Thomas K Avatar answered Sep 28 '22 13:09

Thomas K


Well, what I'd do is to install a different version of Python (2.6 say) and then create a virtualenv and install nose inside that. It will then use that version of nose and keep your stuff isolated.

You can also consider using tox to try to bridge interpreters.

Finally, you can simply run nose python2.6 $(which nose) [other options] args to run nose with the newer Python.

like image 30
Noufal Ibrahim Avatar answered Sep 28 '22 11:09

Noufal Ibrahim