From 10b62ad6bc967e022202d657b7493440fb5cf736 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Jan 22 2020 18:15:19 +0000 Subject: Make assert_error compatible with Python 3.6 The re.Pattern class was introduced in Python 3.7. Use duck-typing to distinguish between str and re pattern object. Fixes: https://pagure.io/freeipa/issue/8179 Signed-off-by: Christian Heimes Reviewed-By: Sergey Orlov --- diff --git a/ipatests/pytest_ipa/integration/tasks.py b/ipatests/pytest_ipa/integration/tasks.py index 0a6a55d..042913f 100755 --- a/ipatests/pytest_ipa/integration/tasks.py +++ b/ipatests/pytest_ipa/integration/tasks.py @@ -1615,7 +1615,7 @@ def assert_error(result, pattern, returncode=None): ``pattern`` may be a ``str`` or a ``re.Pattern`` (regular expression). """ - if isinstance(pattern, re.Pattern): + if hasattr(pattern, "search"): # re pattern assert pattern.search(result.stderr_text), \ f"pattern {pattern} not found in stderr {result.stderr_text!r}" else: