From ee36307441857e47b1b329127ac95cd6f2cf995e Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Tue, 28 May 2019 10:56:11 +0100 Subject: [PATCH] The flaky decorator should go through `(setUp|tearDown)()` at each attempt --- tests/support/helpers.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/support/helpers.py b/tests/support/helpers.py index f9554dcb5b5a..ec5409f18b55 100644 --- a/tests/support/helpers.py +++ b/tests/support/helpers.py @@ -206,10 +206,23 @@ def test_sometimes_works(self): def wrap(cls): for attempt in range(0, attempts): try: + if attempt > 0: + # Run through setUp again + # We only run it after the first iteration(>0) because the regular + # test runner will have already ran setUp the first time + setup = getattr(cls, 'setUp', None) + if callable(setup): + setup() return caller(cls) except Exception as exc: if attempt >= attempts -1: + # We won't try to run tearDown once the attempts are exhausted + # because the regular test runner will do that for us raise exc + # Run through tearDown again + teardown = getattr(cls, 'tearDown', None) + if callable(teardown): + teardown() backoff_time = attempt ** 2 log.info( 'Found Exception. Waiting %s seconds to retry.',