Flush output buffers before exit.

Problem description
===================

When adding support for 2.7 the test exit with os._exit instead of sys.exit() and buffers are not flushed.


Why we got into this (5 whys)
=============================

We did not check the output of tests for previous merge


Changes description
===================

stdout and stderr ar flushed.

How to try and test the changes
===============================

reviewers @alibotean 

Nothing special here.