Unit Testing Guidelines
Guidelines
In general, all functional code should be tested with unit tests. All unit tests should comply with the following requirements:
Unit tests should use the pytest module.
The tests that cover a module called
sibyl-api/path/to/a_module.py
should be implemented in a separated module calledtests/sibyl-api/path/to/test_a_module.py
. Note that the module name has thetest_
prefix and is located in a path similar to the one of the tested module, just inside thetests
folder.Each method of the tested module should have at least one associated test method, and each test method should cover only one use case or scenario.
Test case methods should start with the
test_
prefix and have descriptive names that indicate which scenario they cover. Names such astest_some_methed_input_none
,test_some_method_value_error
ortest_some_method_timeout
are right, but names liketest_some_method_1
,some_method
ortest_error
are not.Each test should validate only what the code of the method being tested does, and not cover the behavior of any third party package or tool being used, which is assumed to work properly as far as it is being passed the right values.
Any third party tool that may have any kind of random behavior, such as some Machine Learning models, databases or Web APIs, can be mocked using the
mock
library, and the only thing that will be tested is that our code passes the right values to them.Unit tests should not use anything from outside the test and the code being tested. This includes not reading or writing to any file system or database, which will be properly mocked.
Last updated