Skip to content

Requesting --capture option to not display all captured output to stdout on test failure #1237

Closed
@hamzasheikh

Description

@hamzasheikh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: capturerelated to the capture builtin pluginplugin: loggingrelated to the logging builtin plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions