Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hamzasheikh opened this issue Dec 7, 2015 · 2 comments
Labels
plugin: capture related to the capture builtin plugin plugin: logging related to the logging builtin plugin

Comments

@hamzasheikh
Copy link

hamzasheikh commented Dec 7, 2015

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

@hamzasheikh
Copy link
Author

Closed PR 1233 based on feedback. Instead of working in the capture area of the code I'll experiment with an additional --tb=style-like flag that will format the captured output.

@Zac-HD Zac-HD added plugin: capture related to the capture builtin plugin plugin: logging related to the logging builtin plugin labels Oct 19, 2018
@blueyed
Copy link
Contributor

blueyed commented Oct 28, 2019

--show-capture=no ?
(assuming this is answered)

@blueyed blueyed closed this as completed Oct 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: capture related to the capture builtin plugin plugin: logging related to the logging builtin plugin
Projects
None yet
Development

No branches or pull requests

3 participants