Page MenuHomePhabricator

site_tests.TestImageUsage,tests_image_usage: AssertionError during site.login()
Open, HighPublic

Description

[00:23:34] ======================================================================
[00:23:34] FAIL: test_image_usage (tests.site_tests.TestImageUsage)
[00:23:34] Test the site.imageusage() method.
[00:23:34] ----------------------------------------------------------------------
[00:23:34] Traceback (most recent call last):
[00:23:34]   File "C:\projects\pywikibot-g4xqx\tests\site_tests.py", line 1115, in test_image_usage
[00:23:34]     iu = list(mysite.imageusage(imagepage, total=10))
[00:23:34]   File "C:\projects\pywikibot-g4xqx\pywikibot\data\api.py", line 2628, in __iter__
[00:23:34]     self.data = self.request.submit()
[00:23:34]   File "C:\projects\pywikibot-g4xqx\pywikibot\data\api.py", line 2061, in submit
[00:23:34]     self._data = super().submit()
[00:23:34]   File "C:\projects\pywikibot-g4xqx\pywikibot\data\api.py", line 1816, in submit
[00:23:34]     if self._userinfo_query(result):
[00:23:34]   File "C:\projects\pywikibot-g4xqx\pywikibot\data\api.py", line 1629, in _userinfo_query
[00:23:34]     self._relogin(message)
[00:23:34]   File "C:\projects\pywikibot-g4xqx\pywikibot\data\api.py", line 1616, in _relogin
[00:23:34]     self.site._relogin()
[00:23:34]   File "C:\projects\pywikibot-g4xqx\pywikibot\site\__init__.py", line 353, in _relogin
[00:23:34]     self.login()
[00:23:34]   File "C:\projects\pywikibot-g4xqx\pywikibot\tools\__init__.py", line 1479, in wrapper
[00:23:34]     return obj(*__args, **__kw)
[00:23:34]   File "C:\projects\pywikibot-g4xqx\pywikibot\site\__init__.py", line 339, in login
[00:23:34]     assert self.userinfo['name'] == self.username()  # load userinfo
[00:23:34] AssertionError
[00:23:34]

https://ci.appveyor.com/project/Ladsgroup/pywikibot-g4xqx/builds/37409982/job/n6tm8liq3o4qbqpd

assert Statement was introduced with rPWBCba26aa2d5ff9e59409052421162ea492cea44f18

Event Timeline

Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. · View Herald Transcript
Xqt triaged this task as High priority.Jan 23 2021, 12:02 PM

Change 657967 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [tests] Give a more informative AssertionError

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

Xqt removed Xqt as the assignee of this task.Jan 23 2021, 12:15 PM

Change 657967 merged by jenkins-bot:
[pywikibot/core@master] [tests] Give a more informative AssertionError

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

==================================== ERRORS ====================================
____________ ERROR at setup of TestUserRecentChanges.test_patrolled ____________

cls = <class 'tests.site_tests.TestUserRecentChanges'>

    @classmethod
    def setUpClass(cls):
        """
        Set up the test class.
    
        Skip the test class if the user config does not have
        a valid login to the site.
        """
        super().setUpClass()
    
        sysop = hasattr(cls, 'sysop') and cls.sysop
    
        for site_dict in cls.sites.values():
            cls.require_site_user(
                site_dict['family'], site_dict['code'], sysop)
    
            if hasattr(cls, 'oauth') and cls.oauth:
                continue
    
            site = site_dict['site']
    
            if site.siteinfo['readonly']:
                raise unittest.SkipTest(
                    'Site {} has readonly state: {}'.format(
                        site, site.siteinfo.get('readonlyreason', '')))
    
            with suppress(NoUsername):
>               site.login()

tests/aspects.py:571: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pywikibot/tools/__init__.py:1479: in wrapper
    return obj(*__args, **__kw)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = APISite("en", "wikipedia"), sysop = None, autocreate = False

    @deprecated_args(sysop=True)
    def login(self, sysop=None, autocreate=False):
        """
        Log the user in if not already logged in.
    
        @param autocreate: if true, allow auto-creation of the account
                           using unified login
        @type autocreate: bool
    
        @raises pywikibot.exceptions.NoUsername: Username is not recognised
            by the site.
        @see: U{https://www.mediawiki.org/wiki/API:Login}
        """
        if sysop is not None:
            issue_deprecation_warning("'sysop' parameter",
                                      warning_class=FutureWarning,
                                      since='20201230')
    
        # TODO: this should include an assert that loginstatus
        #       is not already IN_PROGRESS, however the
        #       login status may be left 'IN_PROGRESS' because
        #       of exceptions or if the first method of login
        #       (below) is successful. Instead, log the problem,
        #       to be increased to 'warning' level once majority
        #       of issues are resolved.
        if self._loginstatus == _LoginStatus.IN_PROGRESS:
            pywikibot.log(
                '{!r}.login() called when a previous login was in progress.'
                .format(self))
        # There are several ways that the site may already be
        # logged in, and we do not need to hit the server again.
        # logged_in() is False if _userinfo exists, which means this
        # will have no effect for the invocation from api.py
        if self.logged_in():
            self._loginstatus = _LoginStatus.AS_USER
            return
        # check whether a login cookie already exists for this user
        # or check user identity when OAuth enabled
        self._loginstatus = _LoginStatus.IN_PROGRESS
        try:
            del self.userinfo  # force reload
            if self.userinfo['name'] == self.user():
                return
        # May occur if you are not logged in (no API read permissions).
        except api.APIError:
            pass
        except NoUsername as e:
            if not autocreate:
                raise e
    
        if self.is_oauth_token_available():
            if self.userinfo['name'] != self.username():
                if self.username() is None:
                    raise NoUsername('No username has been defined in your '
                                     'user-config.py: you have to add in this '
                                     'file the following line:\n'
                                     "usernames['{family}']['{lang}'] "
                                     "= '{username}'"
                                     .format(family=self.family,
                                             lang=self.lang,
                                             username=self.userinfo['name']))
                else:
                    raise NoUsername('Logged in on {site} via OAuth as '
                                     '{wrong}, but expect as {right}'
                                     .format(site=self,
                                             wrong=self.userinfo['name'],
                                             right=self.username()))
            else:
                raise NoUsername('Logging in on %s via OAuth failed' % self)
        login_manager = api.LoginManager(site=self, user=self.username())
        if login_manager.login(retry=True, autocreate=autocreate):
            self._username = login_manager.username
            del self.userinfo  # force reloading
    
            # load userinfo
            assert self.userinfo['name'] == self.username(), \
>               '{} != {}'.format(self.userinfo['name'], self.username())
E           AssertionError: 104.154.182.187 != Pywikibot-test

pywikibot/site/__init__.py:342: AssertionError