Home - WeichselRiver/manual GitHub Wiki
Minimal example math_func.py
When excecuted, pytest looks for functions which names start with "test_" and automatically runs them ...
import pytest
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 4
Run example:
(env) PS C:\Users\cweic\code\playground4> pytest .\math_func.py
If assertion of test function equals true, pytest will the following message:
============================================================ 1 passed in 0.04s =============================================================
(env) PS C:\Users\cweic\code\playground4> pytest .\math_func.py
=========================================================== test session starts ============================================================
platform win32 -- Python 3.9.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: C:\Users\cweic\code\playground4
collected 1 item
math_func.py .
============================================================ 1 passed in 0.03s =============================================================
(env) PS C:\Users\cweic\code\playground4>
In case the assertion equals false, the output looks like:
math_func.py F [100%]
================================================================= FAILURES =================================================================
_______________________________________________________________ test_answer ________________________________________________________________
def test_answer():
> assert inc(3) == 5
E assert 4 == 5
E + where 4 = inc(3)
math_func.py:9: AssertionError
========================================================= short test summary info ==========================================================
FAILED math_func.py::test_answer - assert 4 == 5
============================================================ 1 failed in 0.15s =============================================================
(env) PS C:\Users\cweic\code\playground4>