Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make nosetests use python3

Tags:

python

nose

I try to use nosetests
❯ nosetests '/pathTo/test'

but it uses python 2.7 for my tests:

sys.version_info(major=2, minor=7, micro=5, releaselevel='final', serial=0) 

So some of them fails, because they were written in python 3.3.

I work it around and installed virtual environment:

pyvenv-3.3 py3env 

Activated it:

source ~/py3env/bin/activate 

Check python virsion in virtual environment:

❯ python --version                                                                                 ⏎ Python 3.3.3 (py3env) 

Ok. But nosetest still uses python2.7 even in virtual environment:

sys.version_info(major=2, minor=7, micro=5, releaselevel='final', serial=0) 

So my tests fails. How to make nose use python3?

like image 655
Maxim Yefremov Avatar asked Apr 01 '14 07:04

Maxim Yefremov


People also ask

Which command is used to run nose tests?

Basic Usage 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.

What is nose in python?

Nose is a popular test automation framework in Python that extends unittest to make testing easier. The other advantages of using the Nose framework are the enablement of auto discovery of test cases and documentation collection.

What is Django nose?

django-nose provides all the goodness of nose in your Django tests, like: Testing just your apps by default, not all the standard ones that happen to be in INSTALLED_APPS. Running the tests in one or more specific modules (or apps, or classes, or folders, or just running a specific test)


Video Answer


2 Answers

In Python 3.4 and higher versions: in order to make nose use python3 just run ...

python3 -m "nose" 

... in the target directory with the tests.

The environment setups are not required.

like image 111
Maxim Yefremov Avatar answered Oct 02 '22 20:10

Maxim Yefremov


To install:

sudo apt-get install python-nose python3-nose

To run:

nosetests-2.7 ; nosetests3

This runs the test suite under both PY2 and PY3.

like image 27
ArekBulski Avatar answered Oct 02 '22 18:10

ArekBulski