-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d3ec77
commit 9c131c1
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |