diff --git a/rhodecode/tests/utils.py b/rhodecode/tests/utils.py --- a/rhodecode/tests/utils.py +++ b/rhodecode/tests/utils.py @@ -18,6 +18,7 @@ import threading import time +import sys import logging import os.path import subprocess @@ -31,7 +32,7 @@ from urllib.parse import unquote_plus import webob from webtest.app import TestResponse, TestApp -from webtest.compat import print_stderr + import pytest @@ -51,6 +52,10 @@ from rhodecode.tests import login_user_s log = logging.getLogger(__name__) +def print_to_func(value, print_to=sys.stderr): + print(value, file=print_to) + + class CustomTestResponse(TestResponse): def _save_output(self, out): @@ -60,7 +65,7 @@ class CustomTestResponse(TestResponse): def mustcontain(self, *strings, **kw): """ - Assert that the response contains all of the strings passed + Assert that the response contains all the strings passed in as arguments. Equivalent to:: @@ -68,6 +73,8 @@ class CustomTestResponse(TestResponse): assert string in res """ print_body = kw.pop('print_body', False) + print_to = kw.pop('print_to', sys.stderr) + if 'no' in kw: no = kw['no'] del kw['no'] @@ -82,18 +89,18 @@ class CustomTestResponse(TestResponse): for s in strings: if s not in self: - print_stderr(f"Actual response (no {s!r}):") - print_stderr(f"body output saved as `{f}`") + print_to_func(f"Actual response (no {s!r}):", print_to=print_to) + print_to_func(f"body output saved as `{f}`", print_to=print_to) if print_body: - print_stderr(str(self)) + print_to_func(str(self), print_to=print_to) raise IndexError(f"Body does not contain string {s!r}, body output saved as {f}") for no_s in no: if no_s in self: - print_stderr(f"Actual response (has {no_s!r})") - print_stderr(f"body output saved as `{f}`") + print_to_func(f"Actual response (has {no_s!r})", print_to=print_to) + print_to_func(f"body output saved as `{f}`", print_to=print_to) if print_body: - print_stderr(str(self)) + print_to_func(str(self), print_to=print_to) raise IndexError(f"Body contains bad string {no_s!r}, body output saved as {f}") def assert_response(self):