[3.10] bpo-13236: Flush the output stream more often in unittest (GH-29864) (GH-29929)

It can prevent some losses when output to buffered stream..
(cherry picked from commit f42a06ba279c916fb67289e47f9bc60dc5dee4ee)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
4 files changed