1

我有一个包含 python 脚本的文件夹,其中包含我想要对其进行单元测试的文档测试。当我尝试使用这样的一个文件对其进行测试时:

import unittest
suite = unittest.TestSuite()
suite.addTest('/homes/ndeklein/workspace/MS/PyMS/pyMS/baseFunctions.py')
unittest.TextTestRunner().run(suite)

我收到此错误:

TypeError: the test to add must be callable

但是,当我从命令行执行此操作时

python '/homes/ndeklein/workspace/MS/PyMS/pyMS/baseFunctions.py'

有用。

如何使我的文件可调用?

4

1 回答 1

2

addTest需要 aTestCaseTestSuite- 并且您正在传递一个字符串。

看看这里的文档:

http://docs.python.org/library/unittest.html

目前尚不清楚您想要做什么 - 但如果baseFunctions.py定义 的子类TestCase,您可以试试这个:

import unittest
from baseFunctions import MyTestCase

suite = unittest.TestSuite()
suite.addTest(MyTestCase)
unittest.TextTestRunner().run(suite)
于 2012-03-03T16:48:12.583 回答