Notepad/enter/Coding Tips (Classical)/Terminal Tips/Languages/Python/Projects/Testing/Testing in python.md

732 B

Testing functions

Once you have created your definitions you want to put them in a main class and have something to display if the functions passed. For example:

 def test_sum():
    assert sum([1, 2, 3]) == 6, "Should be 6"

def test_sum_tuple():
    assert sum((1, 2, 2)) == 6, "Should be 6"

if __name__ == "__main__":
    test_sum()
    test_sum_tuple()
    print("Everything passed")

This site has several differnt testing methods that can be used with python. Unittest, nose, and pytest are the most commonly used.

How to execute pytest: https://docs.pytest.org/en/latest/

testing paradigms in python

  • tox
  • pytest