Open
Description
What's the problem this feature will solve?
If an env var is set, I'd like to open a port for remote debugging. In doing so, I'd like to prompt in the terminal that it is waiting to start, like this below, in a top-level __init__.py
file of the app:
import logging
import os
logger = logging.getLogger(__name__)
def setup_debugger():
if os.environ.get("REMOTE_DEBUG"):
import debugpy
port = 5678
logger.warning(f"Waiting for remote debugger to connect on port {port}")
debugpy.listen(("0.0.0.0", port))
debugpy.wait_for_client()
setup_debugger()
However, pytest swallows the output, so the terminal output is just hanging blank:
$ pytest
# hanging
Describe the solution you'd like
In a test, I'd typically be able to temporarily silence the output swallowing via the capsys.disabled()
:
def test_disabling_capturing(capsys):
print("this output is captured")
with capsys.disabled():
print("output not captured, going directly to sys.stdout")
print("this output is also captured")
However, capsys
appears only available as a test fixture, and I don't see a public API to disable stdout capture from outside of a test. I'd like a similar API to do so, e.g.:
from pytest import capsys
with capsys.disabled():
logger.warning(f"Waiting for remote debugger to connect on port {port}")
See above in problem description
Alternative Solutions
I can run with the -s
flag (or --capture=tee-sys
), but that causes noisy output since I only care about printing errors from outside of test runs.