Good codebase are well tested, not necessarily in aiming towards 100% test coverage. But core algorithm are at least covered in unittests; and major system workflows, covered in integration tests. While it is a common practice to assume unit tests to be independent and stateless, it is not always true with integration tests.
In this short example we have an integration test where the flow is to first preprocess the item and then compute its score.
1 | import unittest |
If we just run this test case, test_compute_item_score is going to happen before test_preprocess_item, because unittest applies sorting to the tests.
There are two ways to overcome this: 1. disable sorting (left to the reader as an exercise). 2. using cleverly chose test case names (show below).
1 | import unittest |