When testing with pytest, there are times when you want to check not only the result but also the value of a variable in the middle. In conclusion, it will be output if you add the -s option.
$ pytest -s
Consider the following code.
test_one.py
# test_one.py
def test_good():
for i in range(5):
print(i)
assert True
def test_bad():
print('this should fail!')
assert False
When tested without the -s option, there is no output inside the loop.
$ pytest
=========================================================== test session starts ===========================================================
platform darwin -- Python 3.7.0, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
rootdir: /Users/reishimitani/Desktop/d2xx/D2XX
collected 2 items
test_one.py .F [100%]
================================================================ FAILURES =================================================================
________________________________________________________________ test_bad _________________________________________________________________
def test_bad():
print('this should fail!')
> assert False
E assert False
test_one.py:10: AssertionError
---------------------------------------------------------- Captured stdout call -----------------------------------------------------------
this should fail!
========================================================= short test summary info =========================================================
FAILED test_one.py::test_bad - assert False
======================================================= 1 failed, 1 passed in 0.37s =======================================================
Try adding -s with the same code. The output inside the loop is output.
$ pytest -s
=========================================================== test session starts ===========================================================
platform darwin -- Python 3.7.0, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
rootdir: /Users/reishimitani/Desktop/d2xx/D2XX
collected 2 items
test_one.py 0
1
2
3
4
.this should fail!
F
================================================================ FAILURES =================================================================
________________________________________________________________ test_bad _________________________________________________________________
def test_bad():
print('this should fail!')
> assert False
E assert False
test_one.py:10: AssertionError
========================================================= short test summary info =========================================================
FAILED test_one.py::test_bad - assert False
======================================================= 1 failed, 1 passed in 0.34s =======================================================