相关疑难解决方法(0)

__init__为unittest.TestCase

我想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
Run Code Online (Sandbox Code Playgroud)

我希望在整个测试集中只生成一次所有存根.我无法使用,setUpClass()因为我正在使用Python 2.4(我无法在python 2.7上工作).

我在这做错了什么?

我收到此错误:

 `TypeError: __init__() takes 1 argument (2 given)` 
Run Code Online (Sandbox Code Playgroud)

... __init__当我使用命令运行它时,我将所有存根代码移动到其他错误python -m unittest -v test.

python unit-testing

99
推荐指数
2
解决办法
5万
查看次数

标签 统计

python ×1

unit-testing ×1