【发布时间】:2013-06-27 21:08:51
【问题描述】:
我想为 unittest.TestCase 类在初始化时所做的事情添加几件事,但我不知道该怎么做。
现在我正在这样做:
#filename test.py
class TestingClass(unittest.TestCase):
def __init__(self):
self.gen_stubs()
def gen_stubs(self):
# Create a couple of tempfiles/dirs etc etc.
self.tempdir = tempfile.mkdtemp()
# more stuff here
我希望为整组测试只生成一次所有存根。我不能使用setUpClass(),因为我正在使用 Python 2.4(我也无法在 python 2.7 上使用它)。
我在这里做错了什么?
我收到此错误:
`TypeError: __init__() takes 1 argument (2 given)`
...当我使用命令 python -m unittest -v test 运行它时,将所有存根代码移动到 __init__ 时出现其他错误。
【问题讨论】:
标签: python unit-testing