我有一个基本的测试用例类,它的子类应该用flaky decorator(https://github.com/box/flaky)来装饰,换句话说,我想把flaky decorator应用到每个测试用例(测试方法)上,但是从一个基类开始,使用单个位置来装饰每个测试类或测试用例(有很多测试用例…)。你知道吗
但如果我将decorator应用于基类CustomTestCase,它将影响每个方法(包括helper方法、构造函数等)。是否可以将它仅应用于基类中的测试用例(方法以“test”开头)。我试着通过访问self来实现它。\u testMethod inCustomTestCase.setUp设置没有成功。你知道吗
# base class
@flaky(max_runs=3, min_passes=1)
class CustomTestCase(SimpleTestCase):
"""
base class for tests using Selenium.
"""
@classmethod
def setUpClass(cls):
pass
def setUp(self):
pass
# child class - test suite
class TestSomething(CustomTestCase):
"""
This class contains all different tests
"""
def test_something(self):
""" should be decorated by flaky """
self.assertEqual(1, randint(0, 1))
def test_another(self):
self.assertEqual(1, randint(0, 1))
实际上,SetUp方法运行两次并不成问题。关于helper方法,它不应该被重新执行。所以一切都很好
相关问题 更多 >
编程相关推荐