Phantom42 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/330281 )

Change subject: Fix HttpServerProblemTestCase.test_502 failing
......................................................................

Fix HttpServerProblemTestCase.test_502 failing

HttpbinTestCase class moved to aspects.py, pytest_httpbin is now used
instead of httpbin.org site only if test case inherits HttpbinTestCase

Bug: T154452
Change-Id: Ica26594a553de2e4555ffba56056141a56c3c6c5
---
M tests/aspects.py
M tests/http_tests.py
2 files changed, 55 insertions(+), 59 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/81/330281/1

diff --git a/tests/aspects.py b/tests/aspects.py
index 305c4be..813ba08 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -29,7 +29,6 @@
         UITestCase:
             Not integrated; direct subclass of unittest.TestCase.
 """
-import imp
 import inspect
 import itertools
 import os
@@ -60,6 +59,16 @@
     add_metaclass, execute_pwb, DrySite, DryRequest,
     WarningSourceSkipContextManager, AssertAPIErrorContextManager,
 )
+
+try:
+    import pytest_httpbin
+    optional_pytest_httpbin_cls_decorator = 
pytest_httpbin.use_class_based_httpbin
+except ImportError:
+    pytest_httpbin = None
+
+    def optional_pytest_httpbin_cls_decorator(f):
+        """Empty decorator in case pytest_httpbin is not installed."""
+        return f
 
 OSWIN32 = (sys.platform == 'win32')
 
@@ -484,13 +493,10 @@
         if not hasattr(cls, 'sites'):
             return
 
-        # Check is pytest is used and pytest_httpbin module is installed.
-        if hasattr(sys, '_test_runner_pytest'):
-            try:
-                imp.find_module('pytest_httpbin')
-                httpbin_used = True
-            except ImportError:
-                httpbin_used = False
+        if issubclass(cls, HttpbinTestCase):
+            # If test uses httpbin, then check is pytest test runner is used
+            # and pytest_httpbin module is installed.
+            httpbin_used = hasattr(sys, '_test_runner_pytest') and 
pytest_httpbin
         else:
             httpbin_used = False
 
@@ -1658,3 +1664,43 @@
         CapturingTestCase.process_assert,
         CapturingTestCase.patch_assert,
     ]
+
+
+@optional_pytest_httpbin_cls_decorator
+class HttpbinTestCase(TestCase):
+
+    """
+    Custom test case class, which allows doing dry httpbin tests using 
pytest-httpbin.
+
+    Test cases, which use httpbin, need to inherit this class.
+    """
+
+    sites = {
+        'httpbin': {
+            'hostname': 'httpbin.org',
+        },
+    }
+
+    def get_httpbin_url(self, path=''):
+        """
+        Return url of httpbin.
+
+        If pytest is used, returns url of local httpbin server.
+        Otherwise, returns: http://httpbin.org
+        """
+        if hasattr(self, 'httpbin'):
+            return self.httpbin.url + path
+        else:
+            return 'http://httpbin.org' + path
+
+    def get_httpbin_hostname(self):
+        """
+        Return httpbin hostname.
+
+        If pytest is used, returns hostname of local httpbin server.
+        Otherwise, returns: httpbin.org
+        """
+        if hasattr(self, 'httpbin'):
+            return '{0}:{1}'.format(self.httpbin.host, self.httpbin.port)
+        else:
+            return 'httpbin.org'
diff --git a/tests/http_tests.py b/tests/http_tests.py
index 72db94c..f41f930 100644
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -25,57 +25,7 @@
 )
 
 from tests import join_images_path
-from tests.aspects import unittest, TestCase, DeprecationTestCase, 
require_modules
-
-try:
-    import pytest_httpbin
-    optional_pytest_httpbin_cls_decorator = 
pytest_httpbin.use_class_based_httpbin
-except ImportError:
-    pytest_httpbin = None
-
-    def optional_pytest_httpbin_cls_decorator(f):
-        """Empty decorator in case pytest_httpbin is not installed."""
-        return f
-
-
-@optional_pytest_httpbin_cls_decorator
-class HttpbinTestCase(TestCase):
-
-    """
-    Custom test case class, which allows doing dry httpbin tests using 
pytest-httpbin.
-
-    Test cases, which use httpbin, need to inherit this class.
-    """
-
-    sites = {
-        'httpbin': {
-            'hostname': 'httpbin.org',
-        },
-    }
-
-    def get_httpbin_url(self, path=''):
-        """
-        Return url of httpbin.
-
-        If pytest is used, returns url of local httpbin server.
-        Otherwise, returns: http://httpbin.org
-        """
-        if hasattr(self, 'httpbin'):
-            return self.httpbin.url + path
-        else:
-            return 'http://httpbin.org' + path
-
-    def get_httpbin_hostname(self):
-        """
-        Return httpbin hostname.
-
-        If pytest is used, returns hostname of local httpbin server.
-        Otherwise, returns: httpbin.org
-        """
-        if hasattr(self, 'httpbin'):
-            return '{0}:{1}'.format(self.httpbin.host, self.httpbin.port)
-        else:
-            return 'httpbin.org'
+from tests.aspects import unittest, TestCase, DeprecationTestCase, 
HttpbinTestCase, require_modules
 
 
 class HttpTestCase(TestCase):

-- 
To view, visit https://gerrit.wikimedia.org/r/330281
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ica26594a553de2e4555ffba56056141a56c3c6c5
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Phantom42 <nikita...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to