CleanCut / green

Green is a clean, colorful, fast python test runner.
MIT License
785 stars 75 forks source link

Captured stderr doesn't work with logging.streamHandler(), and even then only if there's also Captured stdout. #226

Closed MxFlix closed 3 years ago

MxFlix commented 3 years ago

Using Green 3.2.0 & Python 3.8.2

I found that Captured stderr is only display when there is also something captured in stdout. Additionally, if a logger adds the handler logging.StreamHandler(), which according to the official documentation is supposed to set its output to sys.stderr if nothing else is specified, its output will not appear in the Captured stderr.

import logging
import unittest

logger_default = logging.getLogger("a logger")
logger_not_default = logging.getLogger("another")
# logger_not_default.addHandler(logging.StreamHandler())
logger_default.propagate = False
logger_not_default.propagate = False

class ThisIsATest(unittest.TestCase):
    def test_green(self):
        # print("PRINT")
        logger_default.error("DEFAULT ERROR")
        logger_not_default.error("ERROR")

As it is now, no captured output appears when I run green. Uncommenting the line # print("PRINT") will show both Captured stdout and Captured stderr. Uncommenting the other commented line will make "ERROR" not appear in the Captured stderr anymore, but rather within the execution whenever it happened to be called.

CleanCut commented 3 years ago

Nice catch! Found it, fixed it. 👍

CleanCut commented 3 years ago

Included in version 3.2.1, just released. That's a fun version number! 😆