From my own QGIS plugin, I want to print text to the python console (see motivation below). Most simply, I use
import sys
sys.stdout.write('Outputtext')
And get:
AttributeError: 'NoneType' object has no attribute 'write'
When I open the python console, close it again and start my plugin, it works. Some kind of initialisation routine seems to be missing when used by the plugin.
The background for this - feel free to suggest alternatives
I'd like to use the console as an output for my plugin unit tests:
unittest.TextTestRunner(verbosity=3, stream=sys.stdout).run(suite)
As the console is inside QGIS, it is non-blocking when running the tests (I need to inspect some results in the map, as I will not implement automated checks for all test results that maybe need to be checked. In that sense, it is rather combined unit and integration testing).
Compared to the MessageLog the console provides a better readability (Syntax highlighting.)