jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/752690 )
Change subject: [tests] Remove TestLoginLogout test from site_tests ......................................................................
[tests] Remove TestLoginLogout test from site_tests
TestLoginLogout test should not run in parallel tasks. Otherwise tests could fail when user is logged out.
Bug: T298892 Change-Id: I6590d56b5ae4ccb60579ae30f1dc9fa3117e8446 --- A tests/site_login_logout_tests.py M tests/site_tests.py 2 files changed, 55 insertions(+), 36 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/site_login_logout_tests.py b/tests/site_login_logout_tests.py new file mode 100644 index 0000000..df1ba45 --- /dev/null +++ b/tests/site_login_logout_tests.py @@ -0,0 +1,55 @@ +#!/usr/bin/python3 +"""Test for login and logout methods.""" +# +# (C) Pywikibot team, 2022 +# +# Distributed under the terms of the MIT license. +# +import unittest +from contextlib import suppress + +import pywikibot +from pywikibot.exceptions import APIError + +from tests.aspects import DefaultSiteTestCase + + +class TestLoginLogout(DefaultSiteTestCase): + + """Test for login and logout methods.""" + + login = True + + def test_login_logout(self): + """Validate login and logout methods by toggling the state.""" + site = self.get_site() + loginstatus = pywikibot.login.LoginStatus + + self.assertTrue(site.logged_in()) + self.assertIn(site._loginstatus, (loginstatus.IN_PROGRESS, + loginstatus.AS_USER)) + self.assertIn('_userinfo', site.__dict__.keys()) + + self.assertIsNone(site.login()) + + if site.is_oauth_token_available(): + with self.assertRaisesRegex(APIError, 'cannotlogout.*OAuth'): + site.logout() + self.assertTrue(site.logged_in()) + self.assertIn(site._loginstatus, (loginstatus.IN_PROGRESS, + loginstatus.AS_USER)) + self.assertIn('_userinfo', site.__dict__.keys()) + + # Fandom family wikis don't support API action=logout + elif 'fandom.com' not in site.hostname(): + site.logout() + self.assertFalse(site.logged_in()) + self.assertEqual(site._loginstatus, loginstatus.NOT_LOGGED_IN) + self.assertNotIn('_userinfo', site.__dict__.keys()) + + self.assertIsNone(site.user()) + + +if __name__ == '__main__': # pragma: no cover + with suppress(SystemExit): + unittest.main() diff --git a/tests/site_tests.py b/tests/site_tests.py index d8c1e06..7ffb9a2 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -3580,42 +3580,6 @@ self.assertIsNone(page)
-class TestLoginLogout(DefaultSiteTestCase): - - """Test for login and logout methods.""" - - login = True - - def test_login_logout(self): - """Validate login and logout methods by toggling the state.""" - site = self.get_site() - loginstatus = pywikibot.login.LoginStatus - - self.assertTrue(site.logged_in()) - self.assertIn(site._loginstatus, (loginstatus.IN_PROGRESS, - loginstatus.AS_USER)) - self.assertIn('_userinfo', site.__dict__.keys()) - - self.assertIsNone(site.login()) - - if site.is_oauth_token_available(): - with self.assertRaisesRegex(APIError, 'cannotlogout.*OAuth'): - site.logout() - self.assertTrue(site.logged_in()) - self.assertIn(site._loginstatus, (loginstatus.IN_PROGRESS, - loginstatus.AS_USER)) - self.assertIn('_userinfo', site.__dict__.keys()) - - # Fandom family wikis don't support API action=logout - elif 'fandom.com' not in site.hostname(): - site.logout() - self.assertFalse(site.logged_in()) - self.assertEqual(site._loginstatus, loginstatus.NOT_LOGGED_IN) - self.assertNotIn('_userinfo', site.__dict__.keys()) - - self.assertIsNone(site.user()) - - class TestClearCookies(TestCase): """Test cookies are cleared after logout."""
pywikibot-commits@lists.wikimedia.org