Page MenuHomePhabricator

ui_tests are broken
Closed, ResolvedPublic


On both linux and windows.

The ui_tests exist only in the core repository, however the modules tested are essentially the same code in compat and core.

Event Timeline

valhallasw raised the priority of this task from to Needs Triage.
valhallasw updated the task description. (Show Details)
valhallasw changed Security from none to None.
valhallasw subscribed.

Okay this might sound stupid, but you have to execute it via tests/ Although it doesn't work because then the tests module isn't available.

If you use python tests/ (which is what I've been doing until recently) pywikibot is imported in and the UI class in pywikibot.userinterfaces.terminal_interface_base is already initialized before the test suite had a change to monkey patch it. And that UI class buffers the std* locally so if we monkeypatch sys.std* it after it is initialized pywikibot.output() and the likes are still using the buffered stdout.

Interestingly the tests are importing pywikibot after patching sys.std*, so wouldn't there be it might work, although importing something in test is like importing pywikibot too.

Directly running

PYTHONPATH=. python tests/

also doesn't work for me, so there's probably something else that loads pywikibot before everything is monkey-patched.

Obvious fix would be to not monkeypatch, and to shell out to a new interpreter instead...

Importing something from tests.utils will also import pywikibot. If I move it above the first class which uses unittest it does execute.

Another problem is then, that the std* is a StringIO so only accepts strings but in Python 3, when we encode the colored messages in pywikibot.userinterfaces.terminal_interface_unix.UnixUI.printColorized, it's bytes. I'm not sure if we shouldn't encode it or if it needs to be BytesIO. But afaik sys.__std* are str based in Python 3 so I think they shouldn't be encoded, especially as pywikibot.userinterfaces.terminal_interface_base.UI.printNonColorized does that:

if sys.version_info[0] == 2:                                        
    line = line.encode(self.encoding, 'replace')                    

Although I'm wondering why it does work outside of the test and the logic in printColorized appears more complex so I'm currently not sure how that need to be changed.

jayvdb triaged this task as Medium priority.Nov 29 2014, 5:15 PM
jayvdb updated the task description. (Show Details)
jayvdb added a project: Pywikibot-tests.
jayvdb moved this task from Backlog to Test failures on the Pywikibot-tests board.
gerritbot subscribed.

Change 186336 had a related patch set uploaded (by John Vandenberg):
Fix all but three of the ui_tests on unix


Change 186336 merged by jenkins-bot:
Update ui_tests expected values

jayvdb claimed this task.

@XZise fixed the remaining tests, and more.