[nosetests]
where=source_py2/test_python_toolbox
py3where=source_py3/test_python_toolbox
Making the `nosetests` script select folder by Python version
-
28-06-2022 - |
Вопрос
I used to have this in my setup.cfg
file:
[nosetests]
where=test_python_toolbox
But now I'm supporting Python 2 and Python 3 by supplying two parallel codebases, one in the source_py2
folder and one in the source_py3
folder. setup.py
knows how to check the Python version and choose the correct one. Problem is, I don't know how to make nosetests
, when invoked in the repo root, select the correct folder.
I could have this:
[nosetests]
where=source_py2/test_python_toolbox
But then tests would work only for Python 2. I want them to work for both versions.
I could launch nosetests
with a flag, but I'd rather not.
Решение
Другие советы
Instead of using where
which is deprecated, use tests
and specify multiple tests:
[nosetests]
tests=source_py2/test_python_toolbox, source_py3/test_python_toolbox
This will run both set of tests. For each test, at the very top, before language specific features are in place, add the selection criteria for running 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 python2.6 nose you will get:
S
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK (SKIP=1)
for each test module that has it. The ugly aspect is that you have to inject this code in every test case.
tox can do that via multiple environment specifications, and the changedir
option (just override that per Python version).