Page MenuHomePhabricator

TestShortLink::test_create_short_link sometimes fails with oauth credentials in user-config.py
Closed, DeclinedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

  • checkout pywikibot-git to 77482f4bab1822c7b604f7d1a4787ad2742ec991
  • Python 3.9.13
  • MacOS 12.6.1
  • pytest tests/page_tests.py::TestShortLink::test_create_short_link
  • put the following in user-config.py:
family = 'wikipedia'
mylang = 'en'

authenticate['test.wikipedia.org'] =    (...)

where the ... are valid oauth credentials

What happens?:
Test fails with:

ERROR tests/page_tests.py::TestShortLink::test_create_short_link - pywikibot.exceptions.NoUsernameError: No username has been defined in your user config file: you have to add in this file the following line:

If you comment out the authenticate line, the test passes. This configuration also passes:

family = 'wikipedia'
mylang = 'en'

#authenticate['test.wikipedia.org'] =    (...)                             
authenticate['en.wikipedia.org'] =   (...)

but this fails (i.e. both authenticate lines active):

family = 'wikipedia'
mylang = 'en'

authenticate['test.wikipedia.org'] =    (...)                             
authenticate['en.wikipedia.org'] =   (...)

This smells like the same problem as T336624.

I also see T223865, T244062, and T256540 all of which describe mysterious failures of test_create_short_link which were apparently related to authentication and never completely understood. Might be related.

Event Timeline

OK, I mostly understand what's happening here. My user-config.py defines oauth credentials for {en,test}.wikipedia.org, and those credentials were created to only be valid on those specific projects. test_create_short_link() forces a login to meta, and that's one of the ways this fails.

I think the bottom line here is that the pywikibot system as a whole depends too much on external resources (such as user-config.py) which makes the test suite fragile. There really needs to be a way for the test framework to supply a complete configuration without looking at an external configuration file.

I think the bottom line here is that the pywikibot system as a whole depends too much on external resources (such as user-config.py) which makes the test suite fragile. There really needs to be a way for the test framework to supply a complete configuration without looking at an external configuration file.

I agree.