Unit Testing/Pytest/Create an assert Test
< Unit Testing | Pytest
Create a Python Program
editCreate the following Python program. Save it as multiply.py
def multiply(x, y):
result = x * y
return result
Create a Test Program
editCreate the following Pytest test program. Save it as test_multiply.py
import multiply
def test_multiply():
assert multiply.multiply(2, 2) == 4
Test Success
editTest the program by running pytest in a terminal or command prompt in the same folder as the two programs above and observe the results.
pytest
Test Failure
editChange the multiply source code somehow, such as multiplying by 0 rather than multiplying by y. Test the program by running pytest again and observe the results.