jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/761893 )
Change subject: [bugfix] Never fail RequireLoginMixin during tearDown(). ......................................................................
[bugfix] Never fail RequireLoginMixin during tearDown().
- Tests with RequireLoginMixin should not fail during tearDown and testmethods may be skipped during setUp like it is implemented in setUpClass() - exclude site_login_logout_tests from tests; it is tested by a seprate Login CI action
Bug: T301545 Change-Id: I2660c99a77e95f64b0b700960f580bc8cb810eb8 --- M tests/__init__.py M tests/aspects.py 2 files changed, 19 insertions(+), 8 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/__init__.py b/tests/__init__.py index b54e2c2..b6e5456 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -172,6 +172,7 @@ disabled_test_modules = { 'tests', # tests of the tests package 'l10n', # pywikibot-i18n repository runs it + 'site_login_logout', # separate Login CI action }
disabled_tests = {} # type: Dict[str, List[str]] diff --git a/tests/aspects.py b/tests/aspects.py index cab9da7..ac67b43 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -5,7 +5,7 @@ such as API result caching and excessive test durations. """ # -# (C) Pywikibot team, 2014-2021 +# (C) Pywikibot team, 2014-2022 # # Distributed under the terms of the MIT license. # @@ -588,18 +588,25 @@ Login to the site if it is not logged in. """ super().setUp() - self._reset_login() + self._reset_login(True)
def tearDown(self): """Log back into the site.""" super().tearDown() self._reset_login()
- def _reset_login(self): - """Login to all sites.""" - # There may be many sites, and setUp doesn't know - # which site is to be tested; ensure they are all - # logged in. + def _reset_login(self, skip_if_login_fails: bool = False): + """Login to all sites. + + There may be many sites, and setUp doesn't know which site is to + be tested; ensure they are all logged in. + + .. versionadded:: 7.0 + The `skip_if_login_fails` parameter. + + :param skip_if_login_fails: called with setUp(); if True, skip + the current current test. + """ for site in self.sites.values(): site = site['site']
@@ -608,7 +615,10 @@
if not site.logged_in(): site.login() - assert site.user() + + if skip_if_login_fails and not site.user(): # during setUp() only + self.skipTest('{}: Not able to re-login to {}' + .format(type(self).__name__, site))
def get_userpage(self, site=None): """Create a User object for the user's userpage."""