Creating a "nosetests" script folder using Python version

I used this in my setup.cfg file:

 [nosetests] where=test_python_toolbox 

But now I support Python 2 and Python 3 by supplying two parallel code files: one in the source_py2 folder and one in the source_py3 folder. setup.py knows how to check the version of Python and choose the right one. The problem is that I do not know how to do nosetests when calling in the repo corner, select the desired folder.

I could do this:

 [nosetests] where=source_py2/test_python_toolbox 

But then the tests will only work for Python 2. I want them to work for both versions.

I could run nosetests with a flag, but I would prefer.

+7
python nose
source share
3 answers
 [nosetests] where=source_py2/test_python_toolbox py3where=source_py3/test_python_toolbox 
+6
source share

Instead of using where , which is deprecated, use tests and specify a few tests:

 [nosetests] tests=source_py2/test_python_toolbox, source_py3/test_python_toolbox 

This will launch both test suites. For each test, at the very top, before the special language features are installed, add selection criteria to run the tests. For example, for source_py3 tests add:

 import sys from unittest import SkipTest if sys.version_info < (3, 0): raise SkipTest("must use python 3.0 or greater") 

With the nose of python2.6 you get:

 S ---------------------------------------------------------------------- Ran 1 test in 0.001s OK (SKIP=1) 

for every test module that has it. The ugly aspect is that you have to enter this code in every test case.

+3
source share

tox can do this with a few environment specifications and the changedir parameter (just override this with the Python version).

+1
source share

All Articles