run-tests: extract Popen logic to a single method
This removes 3 lines in total LOC and makes the upcoming changes easier.
Differential Revision: https://phab.mercurial-scm.org/D948
#require docutils gettext $ $TESTDIR/check-gendoc pt_BR checking for parse errors