我试图创建一个unittest TestCase的实例,以便使用该类的变量和方法,但它给我带来了一个错误:
In [1]: import tests
In [2]: obj = tests.TestDailyAggregations()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-2-6a5e2091c8a1> in <module>()
----> 1 obj = tests.TestDailyAggregations()
/usr/lib/python2.7/unittest/case.py in __init__(self, methodName)
187 except AttributeError:
188 raise ValueError("no such test method in %s: %s" %
--> 189 (self.__class__, methodName))
190 self._testMethodDoc = testMethod.__doc__
191 self._cleanups = []
ValueError: no such test method in <class 'tests.TestDailyAggregations'>: runTest
以下是我的测试.py我要在其中生成TestDailyAggregations实例并在TestWeeklyAggregations中使用其变量user_daily_dict的文件:
^{pr2}$我该怎么做才能成为实例?在
您只需通过向它传递包含的methodName(例如,
setUp
)来实例化它。下面是TestCase
类的代码,如您所见:实例化后,您可以访问它包含的方法。 (我经常用这个技巧调试我的unittest…)
相关问题 更多 >
编程相关推荐