在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 (而不安装额外的模块!)中以最优雅的方式实现这一点?
我认为这是一个副本从:Python:如何运行unittest.main()在一个子目录中的所有源文件?
您应该尝试使用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()