tests: use proctutil.stdout.write() instead of print() in test-extension.t
authorPulkit Goyal <7895pulkit@gmail.com>
Thu, 18 Jun 2020 17:54:39 +0530
changeset 44987 a28d1eca6507
parent 44986 0ff59434af72
child 44988 fa151f7af275
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.
tests/test-extension.t
--- a/tests/test-extension.t	Wed Jan 08 11:33:41 2020 -0500
+++ b/tests/test-extension.t	Thu Jun 18 17:54:39 2020 +0530
@@ -152,21 +152,25 @@
   > 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 @@
   > uisetup = eh.finaluisetup
   > revsetpredicate = eh.revsetpredicate
   > 
-  > bytesname = name.encode('utf-8')
   > # custom predicate to check registration of functions at loading
   > from mercurial import (
   >     smartset,