简体   繁体   English

使用鼻子测试混合的python2和python3代码

[英]Using nose to test mixed python2 and python3 code

I have a project that has both python2 and python3 code in it (its a client/server thing; the server is python3 but there are python2 and python3 clients). 我有一个项目,其中同时包含python2和python3代码(它是客户端/服务器的东西;服务器是python3,但是有python2和python3客户端)。 I'm using nose to handle unit testing. 我正在使用鼻子来处理单元测试。 The directory layout is (currently) basically like 目录布局基本上(当前)类似于

client2
    tests
client3
    tests
server
    tests

Is there a way to set up or use nose so that running node with python2 gets just the python2 tests, and similarly python3. 有没有一种方法可以设置或使用鼻子,以便使用python2运行的节点仅获得python2测试,以及类似的python3。 For instance, something like: 例如,类似:

client2
    tests2
client3
    tests3
server
    tests3

... with some suitable nose arguments. ...带有一些合适的鼻子参数。 I messed around with the -m option but couldn't get anywhere. 我弄乱了-m选项,但无法到达任何地方。

Looks like you will need a combo of --where and --py3where : 看起来你需要的组合--where--py3where

--py3where: --py3where:

Look for tests in this directory under Python 3.x. 在Python 3.x下的此目录中查找测试。 Functions the same as 'where', but only applies if running under Python 3.x or above. 功能与“ where”相同,但仅在Python 3.x或更高版本下运行时适用。 Note that, if present under 3.x, this option completely replaces any directories specified with 'where', so the 'where' option becomes ineffective. 请注意,如果在3.x下存在此选项,则此选项将完全替换用“ where”指定的所有目录,因此“ where”选项无效。 [NOSE_PY3WHERE] [NOSE_PY3WHERE]

So for you it would be something like this: 因此,对您而言,它将是这样的:

nosetests --where=. --where=client2 --py3where=. --py3where=client3 --py3where=server -v

When using nosetests with python3 it will run client3 and server tests only. 当将nastest与python3一起使用时,它将仅运行client3server测试。 When running on python2 it will run client2 tests only. 在python2上运行时,它将仅运行client2测试。

Also, have a look at this question and answers for alternatives. 另外,请查看此问题和替代方法的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM