用鼻子测试python2和python3混合cod

2024-07-08 07:59:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个项目包含python2和python3代码(这是一个客户机/服务器的东西;服务器是python3,但有python2和python3客户端)。我用鼻子来处理单元测试。目录布局(目前)基本上是

client2
    tests
client3
    tests
server
    tests

有没有一种方法可以设置或使用nose,以便用python2运行node只得到python2测试,类似于python3。例如,类似于:

^{pr2}$

。。。有一些合适的理由。我把-m选项搞得一团糟,但哪儿也去不了。在


Tags: 项目代码服务器目录客户端客户机servertests
1条回答
网友
1楼 · 发布于 2024-07-08 07:59:52

看起来您需要 where py3where的组合:

py3where:

Look for tests in this directory under Python 3.x. Functions the same as 'where', but only applies if running under Python 3.x or above. Note that, if present under 3.x, this option completely replaces any directories specified with 'where', so the 'where' option becomes ineffective. [NOSE_PY3WHERE]

对你来说应该是这样的:

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

当对python3使用nosetests时,它将只运行client3和{}测试。在python2上运行时,它将只运行client2测试。在

另外,请查看this question and answers中的备选方案。在

相关问题 更多 >

    热门问题