Use the -s option:

pytest -s

Detailed answer

From the docs:

During test execution any output sent to stdout and stderr is captured. If a test or a setup method fails its according captured output will usually be shown along with the failure traceback.

pytest has the option --capture=method in which method is per-test capturing method, and could be one of the following: fd, sys or no. pytest also has the option -s which is a shortcut for --capture=no, and this is the option that will allow you to see your print statements in the console.

pytest --capture=no     # show print statements in console
pytest -s               # equivalent to previous command

Setting capturing methods or disabling capturing

There are two ways in which pytest can perform capturing:

  1. file descriptor (FD) level capturing (default): All writes going to the operating system file descriptors 1 and 2 will be captured.

  2. sys level capturing: Only writes to Python files sys.stdout and sys.stderr will be captured. No capturing of writes to filedescriptors is performed.

pytest -s            # disable all capturing
pytest --capture=sys # replace sys.stdout/stderr with in-mem files
pytest --capture=fd  # also point filedescriptors 1 and 2 to temp file
Answer from lmiguelvargasf on Stack Overflow
🌐
pytest
docs.pytest.org › en › stable › how-to › output.html
Managing pytest’s output - pytest documentation
Running pytest --no-header with a value of 2 would have the same output as the first verbosity example, but each test inside the file gets its own line in the output. The -r flag can be used to display a “short test summary info” at the end of the test session, making it easy in large test suites to get a clear picture of all failures, skips, xfails, etc. It defaults to fE to list failures and errors. ... # content of test_example.py import pytest @pytest.fixture def error_fixture(): assert 0 def test_ok(): print("ok") def test_fail(): assert 0 def test_error(error_fixture): pass def test_skip(): pytest.skip("skipping this test") def test_xfail(): pytest.xfail("xfailing this test") @pytest.mark.xfail(reason="always xfail") def test_xpass(): pass
Top answer
1 of 14
561

Use the -s option:

pytest -s

Detailed answer

From the docs:

During test execution any output sent to stdout and stderr is captured. If a test or a setup method fails its according captured output will usually be shown along with the failure traceback.

pytest has the option --capture=method in which method is per-test capturing method, and could be one of the following: fd, sys or no. pytest also has the option -s which is a shortcut for --capture=no, and this is the option that will allow you to see your print statements in the console.

pytest --capture=no     # show print statements in console
pytest -s               # equivalent to previous command

Setting capturing methods or disabling capturing

There are two ways in which pytest can perform capturing:

  1. file descriptor (FD) level capturing (default): All writes going to the operating system file descriptors 1 and 2 will be captured.

  2. sys level capturing: Only writes to Python files sys.stdout and sys.stderr will be captured. No capturing of writes to filedescriptors is performed.

pytest -s            # disable all capturing
pytest --capture=sys # replace sys.stdout/stderr with in-mem files
pytest --capture=fd  # also point filedescriptors 1 and 2 to temp file
2 of 14
516

By default, py.test captures the result of standard out so that it can control how it prints it out. If it didn't do this, it would spew out a lot of text without the context of what test printed that text.

However, if a test fails, it will include a section in the resulting report that shows what was printed to standard out in that particular test.

For example,

def test_good():
    for i in range(1000):
        print(i)

def test_bad():
    print('this should fail!')
    assert False

Results in the following output:

>>> py.test tmp.py
============================= test session starts ==============================
platform darwin -- Python 2.7.6 -- py-1.4.20 -- pytest-2.5.2
plugins: cache, cov, pep8, xdist
collected 2 items

tmp.py .F

=================================== FAILURES ===================================
___________________________________ test_bad ___________________________________

    def test_bad():
        print('this should fail!')
>       assert False
E       assert False

tmp.py:7: AssertionError
------------------------------- Captured stdout --------------------------------
this should fail!
====================== 1 failed, 1 passed in 0.04 seconds ======================

Note the Captured stdout section.

If you would like to see print statements as they are executed, you can pass the -s flag to py.test. However, note that this can sometimes be difficult to parse.

>>> py.test tmp.py -s
============================= test session starts ==============================
platform darwin -- Python 2.7.6 -- py-1.4.20 -- pytest-2.5.2
plugins: cache, cov, pep8, xdist
collected 2 items

tmp.py 0
1
2
3
... and so on ...
997
998
999
.this should fail!
F

=================================== FAILURES ===================================
___________________________________ test_bad ___________________________________

    def test_bad():
        print('this should fail!')
>       assert False
E       assert False

tmp.py:7: AssertionError
====================== 1 failed, 1 passed in 0.02 seconds ======================
Discussions

python - How to see normal stdout/stderr console print() output from code during a pytest run? - Stack Overflow
Sometimes I want to just insert some print statements in my code, and see what gets printed out when I exercise it. My usual way to "exercise" it is with existing pytest tests. But when I run these, I don't seem able to see any standard output (at least from within PyCharm, my IDE). More on stackoverflow.com
🌐 stackoverflow.com
How do I print to the console in pytest? - TestMu AI Community
How do I print to the console in pytest? I am using pytest to run my tests, but print statements do not appear in the console output. The documentation suggests that print should work by default. Here is the test code I’m running with pytest my_tests.py: import myapplication as tum class ... More on community.testmuai.com
🌐 community.testmuai.com
0
September 2, 2024
Can't print output to console (for multithreaded tests using pytest-xdist)
Hello, I've made a few tests using SeleniumBase and I can't get the prints inside of my code to show in the Command Line output. I tried using the -s argument, using with capsys.disabled():, or using any of the capture options, setting them inside of a pytest.ini didn't help either. More on github.com
🌐 github.com
4
April 20, 2022
pytest not printing output
If you want to see coverage you need to run coverage command More on reddit.com
🌐 r/django
5
1
November 18, 2024
🌐
pytest
docs.pytest.org › en › stable › how-to › capture-stdout-stderr.html
How to capture stdout/stderr output - pytest documentation
pytest -s # disable all capturing pytest --capture=sys # replace sys.stdout/stderr with in-mem files pytest --capture=fd # also point filedescriptors 1 and 2 to temp file pytest --capture=tee-sys # combines 'sys' and '-s', capturing sys.stdout/stderr # and passing it along to the actual sys.stdout/stderr · One primary benefit of the default capturing of stdout/stderr output is that you can use print statements for debugging:
🌐
GitHub
github.com › pytest-dev › pytest-print
GitHub - pytest-dev/pytest-print: pytest-print adds the printer fixture you can use to print messages to the user (directly to the pytest runner, not stdout) · GitHub
If you need nested messages you can use the printer_factory fixture or the pprinter. from __future__ import annotations from typing import TYPE_CHECKING import pytest from pytest_print import Formatter if TYPE_CHECKING: from pytest_print import PrettyPrinter, PrettyPrinterFactory @pytest.fixture(scope="session") def pretty(create_pretty_printer: PrettyPrinterFactory) -> PrettyPrinter: formatter = Formatter( indentation=" I ", head=" H ", space=" S ", icon="🧹", timer_fmt="[{elapsed:.5f}]", ) return create_pretty_printer(formatter=formatter) def test_long_running(pretty: PrettyPrinter) -> None: pretty("Starting test") pretty_printer_1 = pretty.indent(icon="🚀") pretty_printer_1("Drill down to 1st level details") pretty_printer_2 = pretty_printer_1.indent(icon="🚀") pretty_printer_2("Drill down to 2nd level details") pretty("Finished test")
Starred by 80 users
Forked by 9 users
Languages   Python
🌐
pytest
docs.pytest.org › en › 7.1.x › how-to › output.html
Managing pytest’s output — pytest documentation
Each test inside the file gets its own line in the output. test_words_fail now shows the two failing lists in full, in addition to which index differs. test_numbers_fail now shows a text diff of the two dictionaries, truncated. test_long_text_fail no longer truncates the right hand side of the in statement, because the internal threshold for truncation is larger now (2400 characters currently). ... $ pytest --no-header -vv =========================== test session starts ============================ collecting ...
🌐
PythonTest
pythontest.com › framework › pytest › pytest-logging-real-time
pytest debug print logging in real time | PythonTest
June 30, 2025 - import time def test_1(): print('test_1') time.sleep(1) print('after 1 sec') time.sleep(1) print('after 2 sec') time.sleep(1) print('after 3 sec') assert 1, 'should pass' def test_2(): print('in test_2') time.sleep(1) print('after 1 sec') time.sleep(1) print('after 2 sec') time.sleep(1) print('after 3 sec') assert 0, 'failing for demo purposes' If I just run this normally, pytest will capture all of the output, save it until all of the tests are finished, and display output from the failing tests.
Find elsewhere
🌐
Medium
pavolkutaj.medium.com › how-to-test-printed-output-in-python-with-pytest-and-its-capsys-fixture-161010cfc5ad
How to Test Printed Output in Python with Pytest and its Capsys Fixture | by Pavol Z. Kutaj | Medium
May 15, 2024 - inside the function, we call my_function(), which presumably prints multiple outputs. use the readouterr() method of the capsys fixture to capture the outputs. this method returns a named tuple with two attributes: out and err, which contain ...
🌐
PyPI
pypi.org › project › pytest-print
pytest-print
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Better Stack
betterstack.com › community › questions › how-to-view-standard-print-output-during-a-pytest-run
How to See Normal Print Output During Pytest Run? | Better Stack Community
July 18, 2024 - However, you might want to see all output, even for passing tests. To view print statements or logs during testing, use the -s option: ... The -s option is shorthand for --capture=no, which disables pytest's output capture.
🌐
pytest
docs.pytest.org › en › 6.2.x › capture.html
Capturing of the stdout/stderr output — pytest documentation
April 5, 2022 - 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" print("next") captured = capsys.readouterr() assert captured.out == "next\n" The readouterr() call snapshots the output so far - and capturing will be continued. After the test function finishes the original streams will be restored. Using capsys this way frees your test from having to care about setting/resetting output streams and also interacts well with pytest’s own per-test capturing.
🌐
TestMu AI Community
community.testmuai.com › ask a question
How do I print to the console in pytest? - TestMu AI Community
September 2, 2024 - How do I print to the console in pytest? I am using pytest to run my tests, but print statements do not appear in the console output. The documentation suggests that print should work by default. Here is the test code I’m running with pytest my_tests.py: import myapplication as tum class TestBlogger: @classmethod def setup_class(self): self.user = “alice” self.b = tum.Blogger(self.user) print(“This should be printed, but it won’t be!”) def test_inherit(self): assert issubclass(tum.Blogge...
🌐
pytest
docs.pytest.org › en › 7.1.x › how-to › capture-stdout-stderr.html
How to capture stdout/stderr output — pytest documentation
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" print("next") captured = capsys.readouterr() assert captured.out == "next\n" The readouterr() call snapshots the output so far - and capturing will be continued. After the test function finishes the original streams will be restored. Using capsys this way frees your test from having to care about setting/resetting output streams and also interacts well with pytest’s own per-test capturing.
🌐
Improve & Repeat
improveandrepeat.com › 2020 › 11 › python-friday-45-show-the-print-output-in-the-test-summary
#45: Show the Print() Output in the Test Summary - Python Friday
To change the default behaviour, we can run pytest with the -s flag and our output is back: Now that this obstacle is removed, I am back on track to learn more about test fixtures. Until I know enough to blog about it, I will look at other interesting parts of pytest.
🌐
Continuously Merging
articles.mergify.com › pytest-show-print-statements
How to pytest show print statements During Tests
May 16, 2025 - Pytest captures print statements by default. This means they won't immediately show up in your console. This isn't an error, but a deliberate design choice. Pytest prioritizes clean, concise test results, highlighting pass/fail outcomes rather than the internal workings of your code. This keeps the output focused, especially useful when running extensive test suites.
🌐
Pytest with Eric
pytest-with-eric.com › pytest-best-practices › pytest-logging
How To Use Pytest Logging And Print To Console And File (A Practical Guide) | Pytest with Eric
July 12, 2023 - pytest-print enables you to print messages to stdout during test execution, providing additional visibility of log outputs.
🌐
Pytest with Eric
pytest-with-eric.com › configuration › pytest-stdout
The Ultimate Guide To Capturing Stdout/Stderr Output In Pytest | Pytest with Eric
December 22, 2023 - Now, it’s possible to modify the stdout and stderrcapture behavior in Pytest. Let’s look at the supported settings using a simple example. Here we have 2 tests — test_pass and test_fail . Print passing_test or failing_testmessage to stdout and stderr . Print passing_test or failing_test and os.system subprocess messages to stdout and stderr . Pay close attention to the stdout and stderr sections in the screenshots. All output and errors (even from subprocesses) are captured.
🌐
GitHub
github.com › seleniumbase › SeleniumBase › issues › 1279
Can't print output to console (for multithreaded tests using pytest-xdist) · Issue #1279 · seleniumbase/SeleniumBase
April 20, 2022 - @pytest.fixture(scope="session", params=['male', 'female']) def user_session(request): print('Does this print?
Author   romek-codes
🌐
Continuously Merging
articles.mergify.com › pytest-print-stdout
Pytest Print Stdout: Improve Debugging in Tests
May 17, 2025 - The --capture=no flag, often shortened to -s, disables output capturing entirely. This allows output from your tests, including print statements, to appear in your console immediately.
🌐
Reddit
reddit.com › r/django › pytest not printing output
r/django on Reddit: pytest not printing output
November 18, 2024 -

I'm trying to run some tests in pytest in django. From the snipped, my print statements are not printing anything in the terminal. Anything I'm missing?