Making the `nosetests` script select folder by Python version

核能气质少年 提交于 2019-12-08 18:00:51

问题


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.


回答1:


[nosetests]
where=source_py2/test_python_toolbox
py3where=source_py3/test_python_toolbox



回答2:


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.




回答3:


tox can do that via multiple environment specifications, and the changedir option (just override that per Python version).



来源:https://stackoverflow.com/questions/18804563/making-the-nosetests-script-select-folder-by-python-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!