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 t
Try pytest -s -v test_login.py
for more info in console.
-v
it's a short --verbose
-s
means 'disable all capturing'
pytest --capture=tee-sys
was recently added (v5.4.0). You can capture as well as see the output on stdout/err.
You can also enable live-logging by setting the following in pytest.ini
or tox.ini
in your project root.
[pytest]
log_cli = True
Or specify it directly on cli
pytest -o log_cli=True
The other answers don't work. The only way to see the captured output is using the following flag:
pytest --show-capture all
According to pytest documentation, version 3 of pytest can temporary disable capture in a test:
def test_disabling_capturing(capsys):
print('this output is captured')
with capsys.disabled():
print('output not captured, going directly to sys.stdout')
print('this output is also captured')
When running the test use the -s
option. All print statements in exampletest.py
would get printed on the console when test is run.
py.test exampletest.py -s