Tests¶
At the very least, we aim for 100% line coverage, so automated tests should be added for any new function. Additionally, you should cover as many edge cases as possible, like empty data structures, invalid input, and so on.
File structure¶
Tests belong in the tests
folder. The file structure in the tests folder should mirror the file
structure of the src
folder.
Naming¶
Names of test functions shall start with test_should_
followed by a description of the expected behaviour.
Parametrization¶
Tests should be parametrized using @pytest.mark.parametrize
, even if there is only a single test case. This makes it
easier to add new test cases in the future. Test cases should be given descriptive IDs.
DO (library code):
DON'T (library code):
def test_should_raise_if_equal_to_0(tree_count: int) -> None:
with pytest.raises(ValueError, match="The parameter 'tree_count' has to be greater than 0."):
RandomForestRegressor(tree_count=0)
def test_should_raise_if_less_than_0(tree_count: int) -> None:
with pytest.raises(ValueError, match="The parameter 'tree_count' has to be greater than 0."):
RandomForestRegressor(tree_count=-1)