mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
ipatests: assert_error: allow regexp match
Enhance the assert_error subroutine to provide regular expression matching against the command's stderr output, in additional to substring match. Part of: https://pagure.io/freeipa/issue/8142 Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
This commit is contained in:
parent
aa9340cfdb
commit
3d779b492d
@ -1604,9 +1604,19 @@ def upload_temp_contents(host, contents, encoding='utf-8'):
|
||||
return tmpname
|
||||
|
||||
|
||||
def assert_error(result, stderr_text, returncode=None):
|
||||
"Assert that `result` command failed and its stderr contains `stderr_text`"
|
||||
assert stderr_text in result.stderr_text, result.stderr_text
|
||||
def assert_error(result, pattern, returncode=None):
|
||||
"""
|
||||
Assert that ``result`` command failed and its stderr contains ``pattern``.
|
||||
``pattern`` may be a ``str`` or a ``re.Pattern`` (regular expression).
|
||||
|
||||
"""
|
||||
if isinstance(pattern, re.Pattern):
|
||||
assert pattern.search(result.stderr_text), \
|
||||
f"pattern {pattern} not found in stderr {result.stderr_text!r}"
|
||||
else:
|
||||
assert pattern in result.stderr_text, \
|
||||
f"substring {pattern!r} not found in stderr {result.stderr_text!r}"
|
||||
|
||||
if returncode is not None:
|
||||
assert result.returncode == returncode
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user