【发布时间】:2015-11-30 20:58:27
【问题描述】:
这是我的第一个 Python 项目,我刚刚学习了 unittest 框架。当我执行python test_module.py 时,测试模块运行良好,但是当我想执行文档中所述的某个类或方法时,使用:
python -m unittest test_module.TestClass.test_method # or even just test_module
我收到以下错误:
AttributeError: 'module' object has no attribute 'test_module'
我运行命令的目录包含graphm_test.py(我也尝试将名称更改为test_graphm.py),class graphm_test(unittest.TestCase): 和方法都以test_* 开头,这是我在终端上运行的命令:
python -m unittest test_graphm.py
我在任何地方都找不到与此类似的问题,很高兴知道错误背后的原因以及如何在模块内运行某个类或某个方法
【问题讨论】:
-
考虑使用nosetest 作为您的测试运行器。