Page MenuHomePhabricator

tests_tests fails for HttpServerProblemTestCase.test_502
Closed, ResolvedPublic

Description

==================================== ERRORS ====================================
_____________ ERROR at setup of HttpServerProblemTestCase.test_502 _____________

cls = <class 'tests.tests_tests.HttpServerProblemTestCase'>

    @classmethod
    def setUpClass(cls):
        """
        Set up the test class.
    
        Prevent tests running if the host is down.
        """
        super().setUpClass()
    
        if not hasattr(cls, 'sites'):
            return
    
        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
    
        # If pytest_httpbin will be used during tests, then remove httpbin.org
        # from sites.
        if httpbin_used:
            cls.sites = {k: v for k, v in cls.sites.items()
                         if 'httpbin.org' not in v['hostname']}
    
        for key, data in cls.sites.items():
            if 'hostname' not in data:
                raise Exception('{}: hostname not defined for {}'
                                .format(cls.__name__, key))
            hostname = data['hostname']
    
            if hostname in cls._checked_hostnames:
                if isinstance(cls._checked_hostnames[hostname], Exception):
                    raise unittest.SkipTest(
                        '{}: hostname {} failed (cached): {}'
                        .format(cls.__name__, hostname,
                                cls._checked_hostnames[hostname]))
                elif cls._checked_hostnames[hostname] is False:
                    raise unittest.SkipTest('{}: hostname {} failed (cached)'
                                            .format(cls.__name__, hostname))
                else:
                    continue
    
            e = None
            try:
                if '://' not in hostname:
                    hostname = 'http://' + hostname
                r = http.fetch(hostname,
                               method='HEAD',
                               default_error_handling=False)
                if r.status_code not in {200, 301, 302, 303, 307, 308}:
                    raise ServerError('HTTP status: {}'.format(r.status_code))
            except Exception as e:
                pywikibot.error('{}: accessing {} caused exception:'
                                .format(cls.__name__, hostname))
                pywikibot.exception(e, tb=True)
    
>           if e:
E           UnboundLocalError: local variable 'e' referenced before assignment

tests/aspects.py:467: UnboundLocalError
------------------------------ Captured log setup ------------------------------
ERROR    pywiki:logging.py:101 HttpServerProblemTestCase: accessing http://httpbin.org/status/502 caused exception:
ERROR    pywiki:logging.py:101 HTTP status: 502
Traceback (most recent call last):
  File "/home/travis/build/wikimedia/pywikibot/tests/aspects.py", line 461, in setUpClass
    raise ServerError('HTTP status: {}'.format(r.status_code))
pywikibot.exceptions.ServerError: HTTP status: 50

see rPWBC527a7dfe

Event Timeline

Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. · View Herald Transcript
Xqt triaged this task as High priority.Jan 15 2021, 2:59 PM
Xqt added a subscriber: Mpaa.

Change 656432 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [bugfix] Fix UnboundLocalError in aspects in CheckHostnameMixin

https://gerrit.wikimedia.org/r/656432

Change 656432 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] Fix UnboundLocalError in aspects in CheckHostnameMixin

https://gerrit.wikimedia.org/r/656432

JJMC89 assigned this task to Xqt.
JJMC89 removed a project: Patch-For-Review.