【发布时间】:2018-07-04 01:59:25
【问题描述】:
我的所有测试都有一个父类,它继承自 unittest.TestCase。它包含大量的全局变量,以及一堆用于创建和删除用户和其他实体的自定义函数。
class AutoTest(unittest.TestCase):
def vars(self):
self.api = "http://"
self.auth = HTTPBasicauth("arr", "yarrr")
def new_user(self):
requests.post(url, json, auth)
return response
""""and so on"""
问题是我需要为测试套件准备测试数据,并且应该为套件中的所有测试(即测试类)准备一次。
据我了解,对于这种情况,使用setUpClass,但它仅用作类方法,因此所有定义在父类 ustom 函数中,这对于测试数据准备绝对至关重要,因为它们都是不可调用的实例方法并具有“self”位置参数。
class TestSomeStuff(AutoTests):
def setUpClass(cls):
*and here is the problem, because none of the AutoTest class functions are available*
将不胜感激任何帮助/建议。
【问题讨论】:
-
使用 pytest:docs.pytest.org/en/latest MUCH MUCH 更好....
-
@StephenRauch 同意。但到目前为止必须使用单元测试工作
标签: python-3.x automated-tests python-unittest fixtures