# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 2020-06-18 12:24:39 # Node ID a28d1eca6507d16bf54e5a01146a56873dc10a47 # Parent 0ff59434af72c2b5fae23acdcc1f686ec0bf5ef1 tests: use proctutil.stdout.write() instead of print() in test-extension.t I was debugging this test failure on python3 + chg. I get the following hunk as test failure: ``` @@ -206,6 +206,18 @@ Check normal command's load order of ext 4) bar uipopulate 5) foo reposetup 5) bar reposetup + 4) foo uipopulate (chg !) + 4) bar uipopulate (chg !) + 4) foo uipopulate (chg !) + 4) bar uipopulate (chg !) + 4) foo uipopulate (chg !) + 4) bar uipopulate (chg !) + 4) foo uipopulate (chg !) + 4) bar uipopulate (chg !) + 4) foo uipopulate (chg !) + 4) bar uipopulate (chg !) + 5) foo reposetup (chg !) + 5) bar reposetup (chg !) 0:c24b9ac61126 ``` After hours of debugging and head scracthing, I figured out that something is wrong with output flushing. I initially switched the print() statements to ui.warn() but thanks to Yuya who suggested using procutil.stdout.write() instead. diff --git a/tests/test-extension.t b/tests/test-extension.t --- a/tests/test-extension.t +++ b/tests/test-extension.t @@ -152,21 +152,25 @@ Check that extensions are loaded in phas > from __future__ import print_function > import os > from mercurial import exthelper + > from mercurial.utils import procutil + > + > write = procutil.stdout.write > name = os.path.basename(__file__).rsplit('.', 1)[0] - > print("1) %s imported" % name, flush=True) + > bytesname = name.encode('utf-8') + > write(b"1) %s imported\n" % bytesname) > eh = exthelper.exthelper() > @eh.uisetup > def _uisetup(ui): - > print("2) %s uisetup" % name, flush=True) + > write(b"2) %s uisetup\n" % bytesname) > @eh.extsetup > def _extsetup(ui): - > print("3) %s extsetup" % name, flush=True) + > write(b"3) %s extsetup\n" % bytesname) > @eh.uipopulate > def _uipopulate(ui): - > print("4) %s uipopulate" % name, flush=True) + > write(b"4) %s uipopulate\n" % bytesname) > @eh.reposetup > def _reposetup(ui, repo): - > print("5) %s reposetup" % name, flush=True) + > write(b"5) %s reposetup\n" % bytesname) > > extsetup = eh.finalextsetup > reposetup = eh.finalreposetup @@ -174,7 +178,6 @@ Check that extensions are loaded in phas > uisetup = eh.finaluisetup > revsetpredicate = eh.revsetpredicate > - > bytesname = name.encode('utf-8') > # custom predicate to check registration of functions at loading > from mercurial import ( > smartset,