From 93727abeb8e3d79729cf27e144dd1b32a1480a14 Mon Sep 17 00:00:00 2001 From: sebres Date: Tue, 11 Jun 2019 15:49:04 +0200 Subject: [PATCH] cherry-pick with_alt_time helper decorator from 0.11 --- fail2ban/tests/utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fail2ban/tests/utils.py b/fail2ban/tests/utils.py index 65e09005..d4129b2a 100644 --- a/fail2ban/tests/utils.py +++ b/fail2ban/tests/utils.py @@ -245,6 +245,17 @@ def with_tmpdir(f): shutil.rmtree(tmp) return wrapper +def with_alt_time(f): + """Helper decorator to execute test in alternate (fixed) test time.""" + @wraps(f) + def wrapper(self, *args, **kwargs): + setUpMyTime() + try: + return f(self, *args, **kwargs) + finally: + tearDownMyTime() + return wrapper + # backwards compatibility to python 2.6: if not hasattr(unittest, 'SkipTest'): # pragma: no cover