【问题标题】:Python 2.6.6 unittest test discoveryPython 2.6.6 unittest 测试发现
【发布时间】:2015-09-02 15:16:22
【问题描述】:

在 python 2.7+ 中有很多测试发现的答案,但我需要一个用于 python 2.6.6 的答案。

我有这样的目录结构:

root
|-- runall.py
|-- src
|   |-- a.py
|   |-- b.py
|-- test
    |-- atest.py
    |-- btest.py

我想在runall.py 中加载来自test 的所有测试并使用unittest.main() 运行它们。如何以最优雅的方式在 python 2.6.6 中实现这一点(无需安装额外的模块!)?

【问题讨论】:

  • 你能用unittest2吗?它在 Python 2.7 中具有 unittest 的功能,向后移植到 Python 2.4+。
  • 我没有unittest2
  • 无法安装?
  • 我无法 + 我不想在全球范围内部署各种 python 2.6 env。如果这么简单,我就不会问这个问题了。

标签: python python-2.6 python-unittest


【解决方案1】:

我认为这是来自:Python: How to run unittest.main() for all source files in a subdirectory?

您应该尝试使用nosetests:https://nose.readthedocs.org/en/latest/ 这是一个运行所有测试的非常简单的模块。我们在工作中经常使用它:

这是另一篇帖子的答案,有点骇人听闻,但似乎有效。

dirFoo\
    test.py
    dirBar\
        Foo.py
        Bar.py

dirFoo/test.py 的内容

from dirBar import *
import unittest

if __name__ == "__main__":

    unittest.main()

【讨论】:

  • 不工作:Ran 0 tests in 0.000s。另外,我不能安装任何模块+我不想。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-07
  • 2016-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多