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.
Frage
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?
Lösung
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.
Andere Tipps
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.
I found way to use nosetests with python3 without environment:
cd /Library/Frameworks/Python.framework/Versions/3.3/bin
And then:
❯ nosetests-3.3 '/folder/with/tests'
nosetests-3.3
uses python 3
That's it.
And if your want use command nosetests
instead of nosetests-3.3
, add in ~/.bash_profile
:
nosetests()
{
/Library/Frameworks/Python.framework/Versions/3.3/bin/nosetests-3.3 $1
}
Now you can use:
nosetests '/folder/with/tests'
from any directory. It uses python3
.
This isn't a virtualenv issue as much as a linux issue.
This means that when you use the command nosetests
from the terminal, linux looks within it's available paths (/bin
, /sbin
, or whatever it is by you) for such an executable file.
Your global python 2 nosetests
is found first and executed.
Your virtualenv python3 nosetests
is later in the available path list and therefore never reached.
I would suggest to only install nose or any other python command per virtual environment.