I'm trying to understand how the test suite is architected and not getting very far. Logically what I want is some sort of APISite mock. Looking at the existing core/tests/site_tests.py, it looks like I need to subclass PatchingTestCase, similar to TestRollbackPage. But, when I do that:
class TestGetParsedPage(PatchingTestCase):
"""Test get_parsed_page() site method.""" family = 'wikipedia' code = 'test' login = True @staticmethod @PatchingTestCase.patched(pywikibot.data.api.Request, '_simulate') def _simulate(self, action): """Patch api.Request._simulate. Note: self is the Request instance.""" if action == 'rollback': result = { 'title': self._params['title'][0].title(), 'summary': self._params.get('summary', ['Rollback simulation'])[0], 'last_revid': 381070, } return {action: result} if action and config.simulate and self.write: result = {'result': 'Success', 'nochange': ''} return {action: result} return None @classmethod def setUpClass(cls): """Use sandbox page for tests.""" super().setUpClass() cls.page = pywikibot.Page(cls.site, 'Sandbox') def setUp(self): """Patch has_right method.""" super().setUp() self.patch(self.site, 'has_right', lambda right: True) def test_get_with_default_parser(self): self.assertIsNotEmpty(self.page.title)
I don't even get as far as the test failing. It's just skipped:
Running pytest with args: ['-p', 'vscode_pytest', '--rootdir=/Users/roysmith/dev/pywikibot', '/Users/roysmith/dev/pywikibot/core/tests/site_tests.py::TestGetParsedPage::test_get_with_default_parser'] ============================= test session starts ============================== platform darwin -- Python 3.11.8, pytest-9.0.3, pluggy-1.6.0 rootdir: /Users/roysmith/dev/pywikibot configfile: core/tox.ini collected 1 item
core/tests/site_tests.py s [100%]
============================== 1 skipped in 0.98s ============================== Finished running tests!
On Apr 15, 2026, at 8:27 PM, Huji Lee huji.huji@gmail.com wrote:
Welcome, Roy!
I don't contribute to pwb frequently anymore, which is why I haven't kept my local testing config up to date and am relying on the CI on Gerrit. However, if you intend to contribute regularly (say, once a month or more) then I recommend you get the local testing to work for you. And if some tests are problematic, please feel free to help enhance them.
Could it be because login=True is set and the bot is in a logged out state?
On Fri, Apr 17, 2026 at 1:30 PM Roy Smith roy@panix.com wrote:
I'm trying to understand how the test suite is architected and not getting very far. Logically what I want is some sort of APISite mock. Looking at the existing core/tests/site_tests.py, it looks like I need to subclass PatchingTestCase, similar to TestRollbackPage. But, when I do that:
class TestGetParsedPage(PatchingTestCase):
"""Test get_parsed_page() site method.""" family = 'wikipedia' code = 'test' login = True @staticmethod @PatchingTestCase.patched(pywikibot.data.api.Request, '_simulate') def _simulate(self, action): """Patch api.Request._simulate. Note: self is the Requestinstance.""" if action == 'rollback': result = { 'title': self._params['title'][0].title(), 'summary': self._params.get('summary', ['Rollback simulation'])[0], 'last_revid': 381070, } return {action: result}
if action and config.simulate and self.write: result = {'result': 'Success', 'nochange': ''} return {action: result} return None @classmethod def setUpClass(cls): """Use sandbox page for tests.""" super().setUpClass() cls.page = pywikibot.Page(cls.site, 'Sandbox') def setUp(self): """Patch has_right method.""" super().setUp() self.patch(self.site, 'has_right', lambda right: True) def test_get_with_default_parser(self): self.assertIsNotEmpty(self.page.title)I don't even get as far as the test failing. It's just skipped:
Running pytest with args: ['-p', 'vscode_pytest', '--rootdir=/Users/roysmith/dev/pywikibot', '/Users/roysmith/dev/pywikibot/core/tests/site_tests.py::TestGetParsedPage::test_get_with_default_parser'] ============================= test session starts ============================== platform darwin -- Python 3.11.8, pytest-9.0.3, pluggy-1.6.0 rootdir: /Users/roysmith/dev/pywikibot configfile: core/tox.ini collected 1 item
core/tests/site_tests.py s [100%]
============================== 1 skipped in 0.98s
Finished running tests!
On Apr 15, 2026, at 8:27 PM, Huji Lee huji.huji@gmail.com wrote:
Welcome, Roy!
I don't contribute to pwb frequently anymore, which is why I haven't kept my local testing config up to date and am relying on the CI on Gerrit. However, if you intend to contribute regularly (say, once a month or more) then I recommend you get the local testing to work for you. And if some tests are problematic, please feel free to help enhance them.
Yeah, that was it, thanks. With that hint, I was able to place a breakpoint in RequireLoginMixin.require_site_user() and see it raise unittest.SkipTest:
@classmethod def require_site_user(cls, family, code) -> None: """Check the user config has a valid login to the site.""" if not cls.has_site_user(family, code): raise unittest.SkipTest( f'{cls.__name__}: No username for {family}:{code}')
This may be an interaction with VS Code. This output:
Running pytest with args: ['-p', 'vscode_pytest', '--rootdir=/Users/roysmith/dev/pywikibot', '/Users/roysmith/dev/pywikibot/core/tests/site_tests.py::TestGetParsedPage::test_get_with_default_parser'] ============================= test session starts ============================== platform darwin -- Python 3.11.8, pytest-9.0.3, pluggy-1.6.0 rootdir: /Users/roysmith/dev/pywikibot configfile: core/tox.ini collected 1 item
core/tests/site_tests.py s [100%]
============================== 1 skipped in 0.98s ============================== Finished running tests!
was from the "TEST RESULTS" window of VS Code. If I run it on the command line, I get the same basic result, but it also prints the "TestGetParsedPage: No username for wikipedia:test)" string. Weird.
(pywikibot) roysmith@Roys-Mac-Mini pywikibot % pytest '-vv' '--rootdir=/Users/roysmith/dev/pywikibot' '/Users/roysmith/dev/pywikibot/core/tests/site_tests.py::TestGetParsedPage::test_missing_rights' ========================================================================================================= test session starts ========================================================================================================= platform darwin -- Python 3.11.8, pytest-9.0.3, pluggy-1.6.0 -- /Users/roysmith/dev/pywikibot/venv/bin/python3.11 cachedir: .pytest_cache rootdir: /Users/roysmith/dev/pywikibot configfile: core/tox.ini collected 1 item
core/tests/site_tests.py::TestGetParsedPage::test_missing_rights SKIPPED (TestGetParsedPage: No username for wikipedia:test) [100%]
========================================================================================================= 1 skipped in 1.02s ==========================================================================================================
I asked on StackOverflow https://stackoverflow.com/questions/79927664/how-to-trace-why-a-test-is-being-skipped, where somebody suggested I add "-rs" to the pytest command line. And that did indeed get VS Code to print the reason (even though I didn't need it when run from a shell window).