How to decorate methods of child clutches from base class?

I have a base test class whose subclasses need to be decorated with a broken decorator ( https://github.com/box/flaky ), in other words I want to apply flaky decorator to each test case (test methods), but do it from the base class , use one place instead of decorating each test class or test case (there are many test cases ...).

But if I applied the decorator to the base CustomTestCase class, it affects every method (including helper methods, constructors, etc.). Is it possible to apply it only to test cases (methods start with "test") from the base class. I tried to do this by accessing self._testMethod in CustomTestCase.setUp with no success.

# 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))

      

+3


source to share


1 answer


This is not really a problem when the SetUp method is executed twice. It cannot be repeated about helper methods. So it's okay



0


source







All Articles