jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
aspects.RequireUserMixin: Skip tests if the database is locked

Since the error occures during login, any test that requires user login
should be skipped.
Move the skip routine of TestPageUserAction.setUpClass into RequireUserMixin.

Bug: T216529
Change-Id: I35c3f345d67eea3c760af01dae29a3f850c96434
---
M tests/aspects.py
M tests/page_tests.py
2 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/tests/aspects.py b/tests/aspects.py
index 662c44f..f0045e6 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -627,23 +627,29 @@

sysop = hasattr(cls, 'sysop') and cls.sysop

- for site in cls.sites.values():
- cls.require_site_user(site['family'], site['code'], 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', '')))
+
try:
- site['site'].login(sysop)
+ site.login(sysop)
except NoUsername:
pass

- if not site['site'].user():
+ if not site.user():
raise unittest.SkipTest(
'{}: Not able to login to {} as {}'
- .format(cls.__name__,
- 'sysop' if sysop else 'bot',
- site['site']))
+ .format(cls.__name__, 'sysop' if sysop else 'bot', site))

def setUp(self):
"""
diff --git a/tests/page_tests.py b/tests/page_tests.py
index ab7fd24..0dbd553 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -972,18 +972,6 @@

user = True

- @classmethod
- def setUpClass(cls):
- """Set up the test class.
-
- Check whether the site is write protected and skip the tests then.
- """
- super(TestPageUserAction, cls).setUpClass()
- site = cls.get_site()
- if site.siteinfo['readonly']:
- raise unittest.SkipTest('Site {} has readonly state: {}'.format(
- site, site.siteinfo.get('readonlyreason', '')))
-
def test_purge(self):
"""Test purging the mainpage."""
mainpage = self.get_mainpage()

To view, visit change 491543. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I35c3f345d67eea3c760af01dae29a3f850c96434
Gerrit-Change-Number: 491543
Gerrit-PatchSet: 3
Gerrit-Owner: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)