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

Fix stdout/stderr redirects #25

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
30 changes: 30 additions & 0 deletions tests/benchmarks/test_print.py
art049 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import annotations

import sys
from typing import TYPE_CHECKING

import pytest

if TYPE_CHECKING:
from pytest import CaptureFixture


@pytest.mark.benchmark
def test_print():
"""Test print statements are captured by pytest (i.e., not printed to terminal in
the middle of the progress bar) and only displayed after test run (on failures)."""
print("print to stdout")
print("print to stderr", file=sys.stderr)


@pytest.mark.benchmark
def test_capsys(capsys: CaptureFixture):
"""Test print statements are captured by capsys (i.e., not printed to terminal in
the middle of the progress bar) and can be inspected within test."""
print("print to stdout")
print("print to stderr", file=sys.stderr)

stdout, stderr = capsys.readouterr()

assert stdout == "print to stdout\n"
assert stderr == "print to stderr\n"