jenkins-bot submitted this change.

View Change

Approvals: JJMC89: Looks good to me, approved Don-vip: Looks good to me, but someone else must approve jenkins-bot: Verified
[IMPR] Use unittest_print instead of log for APIError during tests

Revert: [IMPR] Add parameters to APIError to show them
(Bug: T333957) This reverts afab98e

Bug: T369219
Change-Id: Ibe68e4eacb0c88a2421f6458f608de17f2472e19
---
M pywikibot/data/api/_requests.py
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/pywikibot/data/api/_requests.py b/pywikibot/data/api/_requests.py
index 3a4d770..8de80c4 100644
--- a/pywikibot/data/api/_requests.py
+++ b/pywikibot/data/api/_requests.py
@@ -995,6 +995,8 @@

:return: a dict containing data retrieved from api.php
"""
+ test_running = os.environ.get('PYWIKIBOT_TEST_RUNNING', '0') == '1'
+
self._add_defaults()
use_get = self._use_get()
retries = 0
@@ -1137,18 +1139,20 @@
# raise error
try:
param_repr = str(self._params)
- pywikibot.log(
- f'API Error: query=\n{pprint.pformat(param_repr)}')
- pywikibot.log(f' response=\n{result}')
+ msg = (f'API Error: query=\n{pprint.pformat(param_repr)}\n'
+ f' response=\n{result}')
+ if test_running:
+ from tests import unittest_print
+ unittest_print(msg)
+ else:
+ pywikibot.log(msg)

- args = {'param': body} if body else {}
- args.update(error)
- raise pywikibot.exceptions.APIError(**args)
+ raise pywikibot.exceptions.APIError(**error)
except TypeError:
raise RuntimeError(result)

msg = 'Maximum retries attempted due to maxlag without success.'
- if os.environ.get('PYWIKIBOT_TEST_RUNNING', '0') == '1':
+ if test_running:
import unittest
raise unittest.SkipTest(msg)


To view, visit change 1052090. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ibe68e4eacb0c88a2421f6458f608de17f2472e19
Gerrit-Change-Number: 1052090
Gerrit-PatchSet: 7
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Don-vip <vincent.privat@gmail.com>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: jenkins-bot