Page MenuHomePhabricator

TestApiFunctions.testObjectCreation fails with nb-wiki and Python 2.7
Closed, DeclinedPublic

Description

https://api.travis-ci.org/v3/job/669558041/log.txt

======================================================================
FAIL: testObjectCreation (tests.api_tests.TestApiFunctions)
Test api.Request() constructor with implicit site creation.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/wikimedia/pywikibot/pywikibot/tools/__init__.py", line 525, in suppressed_func
    return func(*args, **kwargs)
  File "/home/travis/build/wikimedia/pywikibot/tests/api_tests.py", line 145, in testObjectCreation
    self.assertEqual(req.site, self.get_site())
AssertionError: APISite("test", "wikipedia") != APISite("no", "wikipedia")

----------------------------------------------------------------------
Ran 1912 tests in 937.081s

FAILED (failures=1, skipped=100, expected failures=18)

No idea why the request site differs from default site here.

Event Timeline

Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. · View Herald Transcript

Since this test formerly running on enwiki was fixed to run in nbwiki. It seems the redirection isn't handled somewhere in basic Site() creation, where it should.

Since this test formerly running on enwiki was fixed to run in nbwiki. It seems the redirection isn't handled somewhere in basic Site() creation, where it should.

cannot reproduce it locally neither with Python 3.8 nor with Python 2.7:

C:\pwb\GIT\core>py -2 pwb.py -lang:nb api_tests -v TestApiFunctions
WARNING: C:\pwb\GIT\core\pywikibot\__init__.py:128: FutureWarning:

Python 2.7.17 will be dropped soon.
It is recommended to use Python 3.5 or above.
See T213287 for further information.

  FutureWarning)  # probably adjust the line no in utils.execute()

WARNING: C:\pwb\GIT\core\pywikibot\tools\ip.py:56: ImportWarning: ipaddress backport is defective; patching; install ipaddr
  ImportWarning)

tests: max_retries reduced from 15 to 1
WARNING: C:\pwb\GIT\core\pywikibot\tools\__init__.py:1790: UserWarning: Site wikipedia:no instantiated using different code "nb"
  return obj(*__args, **__kw)

testObjectCreation (__main__.TestApiFunctions)
Test api.Request() constructor with implicit site creation. ... C:\pwb\GIT\core\pywikibot\tools\__init__.py:1790: UserWarning: Site wikipedia:no instantiated using different code "nb"
  return obj(*__args, **__kw)
ok

----------------------------------------------------------------------
Ran 1 test in 1.164s

OK

Could we somehow print the full traceback or more details about this issue?

Change 593917 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [tests] Add unittest_print statements for debugging

https://gerrit.wikimedia.org/r/593917

Change 593917 merged by jenkins-bot:
[pywikibot/core@master] [tests] Add unittest_print statements for debugging

https://gerrit.wikimedia.org/r/593917

Result after changes:

>>> Debugging stuff (T249090) ----

config at method start: test wikipedia

<<< ------------------------------

>>> Debugging stuff (T249090) ----

config: test wikipedia

Request: /w/api.php?action=test&foo=&bar=test

{'write': False, 'mime_params': None, 'throttle': True, 'use_get': None, 'site': APISite("test", "wikipedia"), 'retry_wait': 5, 'max_retries': 2, 'action': u'test', '_warning_handler': None, '_params': {u'action': [u'test'], u'foo': [u''], u'bar': [u'test']}}

config before asserting: test wikipedia

<<< ------------------------------

It kind of looks like config.mylang is overwritten in some place in api_tests.py permanently.

It kind of looks like config.mylang is overwritten in some place in api_tests.py permanently.

pywikibot.Site() is different from TestCase.get_site(). Anyway I am wondering why we have any test site there because TestApiFunctions is a DefaultSiteTestCase and LANGUAGE=nb FAMILY=wikipedia is given here for Travis tests.

Yeah, that's why I feel config.mylang must be overwritten somewhere before this test. user-config.py file still contains mylang = 'nb' when running the test (just tested in https://travis-ci.org/github/dvorapa/pywikibot/builds/682834777#L5707). Or the user-config.py path is overwritten, I don't know.

Ohhhh! Python 2 only issue (2.7.12), just tested 3.5_with_system_site_packages and it worked correctly

Ohhhh! Python 2 only issue (2.7.12), just tested 3.5_with_system_site_packages and it worked correctly

Python 2.7.12 works for me locally. Probably it must be one of the predefined packages then.

Ohhhh! Python 2 only issue (2.7.12), just tested 3.5_with_system_site_packages and it worked correctly

Python 2.7.12 works for me locally. Probably it must be one of the predefined packages then.

That would make sense.

I checked several installations like requests 2.9.1, urllib3 1.13.1, chardet 2.3.0, idna 2.0, enum 1.1.2 but I didn't get this mysterious bug.

I do not find the trick. Therefore I suppose to drop this side-package-test instead of investigate into this matter further. It seems to be related to deprecated Python 2 anyway which is to be dropped soon (and sooner due to this failing test)

Perhaps we could just switch from 2.7_with_system_site_packages to 3.5_with_system_site_packages (there is only 2.7 and 3.5 in Travis)

Perhaps we could just switch from 2.7_with_system_site_packages to 3.5_with_system_site_packages (there is only 2.7 and 3.5 in Travis)

agree

Change 595275 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [cleanup] Remove T249090 debugging stuff

https://gerrit.wikimedia.org/r/595275

Change 595275 merged by jenkins-bot:
[pywikibot/core@master] [cleanup] Remove T249090 debugging stuff

https://gerrit.wikimedia.org/r/595275