Pytest - simple passing test


  • Filename startes with test_
  • A function that starts with test_
  • Call the test function with some parameters and check if the results are as expected.


examples/pytest/math/test_mymath.py

import mymath

def test_add():
    assert mymath.add(2, 2) == 4
pytest test_mymath.py
python -m pytest test_mymath.py

============================= test session starts ==============================
platform linux -- Python 3.8.6, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
rootdir: /home/gabor/work/slides/python/examples/pytest/math
plugins: flake8-1.0.6, dash-1.17.0
collected 1 item

test_mymath.py .                                                         [100%]

============================== 1 passed in 0.00s ===============================

$ echo $?
0

> echo %ERRORLEVEL%
0