Python Unit Test

less than 1 minute read

There are two popular modules for unit test Pythin which are unittest (prebuild with Python package) and pytest

Unit test

Inside the unit test there are several packages such mock

Pytest

For more information about the Pytest, please refer to the link

pytest test_{name of the file}.py

options such verbose to display the percentage of the test coverage

Please refer to the link for more information on the unitest_mock https://docs.python.org/3/library/unittest.mock.html

Most unit test follows this pattern

  • Arrange - declare the arguments
  • Act - declare the function
  • Assert - equal to the intended output https://www.youtube.com/watch?v=sCthIEOaMI8&list=PLJsmaNFr5mNqSeuNepT3IaMrgzRMm9lQR&index=2

Tags:

Updated: