Skip to content

Commit

Permalink
Add print & capsys tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodegard committed Feb 12, 2024
1 parent 3d3ec77 commit 9c131c1
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/benchmarks/test_print.py
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"

0 comments on commit 9c131c1

Please sign in to comment.