【问题标题】:Using nose to test mixed python2 and python3 code使用nose测试混合python2和python3代码
【发布时间】:2014-05-15 08:01:36
【问题描述】:

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

client2
    tests
client3
    tests
server
    tests

有没有办法设置或使用nose,以便使用python2运行节点只获得python2测试,类似地python3。例如,类似:

client2
    tests2
client3
    tests3
server
    tests3

... 带有一些合适的鼻子参数。我搞砸了 -m 选项,但无法到达任何地方。

【问题讨论】:

    标签: python nose


    【解决方案1】:

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

    --py3where:

    在 Python 3.x 下的此目录中查找测试。功能相同 作为 'where',但仅适用于在 Python 3.x 或更高版本下运行。 请注意,如果在 3.x 中存在,此选项将完全替换任何 用 'where' 指定的目录,所以 'where' 选项变为 无效。 [NOSE_PY3WHERE]

    所以对你来说应该是这样的:

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

    在 python3 中使用鼻子测试时,它将仅运行 client3server 测试。在 python2 上运行时,它将仅运行 client2 测试。

    另外,请查看this question and answers 以了解替代方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-13
      • 1970-01-01
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-24
      • 2011-05-07
      相关资源
      最近更新 更多