Closed
Description
I have a use case where tests create debug logs to files (Python's logging module). When a test fails, PyTest displays all captured debug logs to stdout.
The way logging is configured:
import sys
import logging
import logging.handlers
FORMAT = "%(asctime)s : %(name)s : %(module)s : %(funcName)s : %(levelname)s : %(message)s"
date_format = "%Y%m%d-%H%M%S-%f"
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter(fmt=FORMAT)
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setLevel(logging.WARNING)
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
LOG_FILENAME = "{0}.log".format(__name__)
file_handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=100000, backupCount=20)
file_handler.setLevel(logging.DEBUG)
formatter = logging.Formatter(fmt=FORMAT)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
Requesting a fourth option, "forget"*, for --capture
flag that does not output captured output but does preserves and outputs PyTest's own output (results, etc.). I have created PR 1233 with proof of concept patch as well.
* --capure=no
did not capture but let the stdout/stderr output straight through to stdout