2015-09-02 52 views
-1

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

我有这样的目录结构:

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

我想从test加载所有测试runall.pyunittest.main()运行它们。我怎样才能以最优雅的方式在Python 2.6.6(,无需安装额外的模块!)中实现?

+1

的内容,你可以使用['unittest2'(https://pypi.python.org/pypi/unittest2)?它在Python 2.7中具有'unittest'的功能,被反向移植到Python 2.4+。 – Alasdair

+0

我没有'unittest2' – Scony

+1

你无法安装它? – Alasdair

回答

0

我觉得这是一个重复:Python: How to run unittest.main() for all source files in a subdirectory?

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

以下是来自另一个帖子的答案,类似hackish,但似乎工作。

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

dirFoo/test.py

from dirBar import * 
import unittest 

if __name__ == "__main__": 

    unittest.main() 
+0

不工作:'在0.000秒测试0。另外,我不能安装任何模块+我不想。 – Scony

+0

试试这个:http://stackoverflow.com/a/1732477/4080476 –

相关问题