jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1175214?usp=email )

Change subject: Tests: skip test if IP is blocked
......................................................................

Tests: skip test if IP is blocked

This is a temporary solution until T399485 is solved.

Bug: T399367
Change-Id: I05889086b043e19ca24842d570f1a10a33cca04c
---
M pywikibot/data/api/_requests.py
1 file changed, 14 insertions(+), 5 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/pywikibot/data/api/_requests.py b/pywikibot/data/api/_requests.py
index 345b390..248f5e2 100644
--- a/pywikibot/data/api/_requests.py
+++ b/pywikibot/data/api/_requests.py
@@ -44,6 +44,11 @@

 __all__ = ('CachedRequest', 'Request', 'encode_url')

+TEST_RUNNING = os.environ.get('PYWIKIBOT_TEST_RUNNING', '0') == '1'
+
+if TEST_RUNNING:
+    import unittest
+
 # Actions that imply database updates on the server, used for various
 # things like throttling or skipping actions when we're in simulation
 # mode
@@ -753,6 +758,13 @@
 The text message is:
 {text}
 """
+            if TEST_RUNNING:
+                if response.status_code == 402 \
+                   and 'Requests from your IP have been blocked' in text:
+                    raise unittest.SkipTest(msg)  # T399367
+
+                from tests import unittest_print
+                unittest_print(msg)

             # Do not retry for AutoFamily but raise a SiteDefinitionError
             # Note: family.AutoFamily is a function to create that class
@@ -993,8 +1005,6 @@

         :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
@@ -1139,7 +1149,7 @@
                 param_repr = str(self._params)
                 msg = (f'API Error: query=\n{pprint.pformat(param_repr)}\n'
                        f'           response=\n{result}')
-                if test_running:
+                if TEST_RUNNING:
                     from tests import unittest_print
                     unittest_print(msg)
                 else:
@@ -1150,8 +1160,7 @@
                 raise RuntimeError(result)

         msg = 'Maximum retries attempted due to maxlag without success.'
-        if test_running:
-            import unittest
+        if TEST_RUNNING:
             raise unittest.SkipTest(msg)

         raise MaxlagTimeoutError(msg)

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1175214?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I05889086b043e19ca24842d570f1a10a33cca04c
Gerrit-Change-Number: 1175214
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to