Skip to content

stdout capture (capsys) does not seem to work with real-time cli logging #3819

Closed
@Sup3rGeo

Description

@Sup3rGeo
  • Minimal example if possible

Using the snippet from https://docs.pytest.org/en/latest/capture.html#accessing-captured-output-from-a-test-function, just adding a logging call before the second print:

import logging
import sys

logger = logging.getLogger(__name__)

def test_myoutput(capsys):  # or use "capfd" for fd-level
    print("hello")
    sys.stderr.write("world\n")
    captured = capsys.readouterr()
    assert captured.out == "hello\n"
    assert captured.err == "world\n"

    logging.info("something")

    print("next")
    captured = capsys.readouterr()
    assert captured.out == "next\n"

Running with pytest --log-cli-level=INFO makes the test fail as the captured.out variable comes empty.


  • pip list of the virtual environment you are using
venv-clean-py1) D:\VM\pytest-capsys-logging-bug>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
atomicwrites (1.1.5)
attrs (18.1.0)
colorama (0.3.9)
more-itertools (4.3.0)
pip (9.0.1)
pluggy (0.7.1)
py (1.5.4)
pytest (3.7.1)
setuptools (28.8.0)
six (1.11.0)
  • pytest and operating system versions

  • pytest (3.7.1)

  • windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: capturerelated to the capture builtin plugintype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions