# HG changeset patch # User Yuya Nishihara # Date 2017-09-17 03:39:14 # Node ID d6af8da4a3b87fdfd21301c44badd7c8443a2d08 # Parent cd022a11ec8370356b1a3e0e718e32579ae74204 py3: rewrite stdout hack of doctest by using ui.pushbuffer() We can't use pycompat.stdout here because the doctest runner replaces sys.stdout with a string buffer. diff --git a/mercurial/formatter.py b/mercurial/formatter.py --- a/mercurial/formatter.py +++ b/mercurial/formatter.py @@ -45,9 +45,12 @@ Doctest helper: ... import sys ... from . import ui as uimod ... ui = uimod.ui() -... ui.fout = sys.stdout # redirect to doctest ... ui.verbose = verbose -... return fn(ui, ui.formatter(fn.__name__, opts)) +... ui.pushbuffer() +... try: +... return fn(ui, ui.formatter(fn.__name__, opts)) +... finally: +... print(pycompat.sysstr(ui.popbuffer()), end='') Basic example: @@ -101,7 +104,7 @@ bar baz: foo, bar """ -from __future__ import absolute_import +from __future__ import absolute_import, print_function import collections import contextlib