To give a slightly contrived example, let's say I want to test that a function returns two numbers, and that the first one is smaller than the second one:
result = my_function()
assert len(result) == 2
a, b = my_function()
assert a < b
test_length fails, then
test_order will fail too. Is it a best practice to write
test_length, or to skip it?
EDIT: note that in this situation, both tests are mostly independent from each other, each one can be run in isolation, or they could be run in reverse order, this does not matter. So none of these former questions
- How should I test the functionality of a function that uses other functions in it?
- Do I need unit test if I already have integration test?
- How to structure tests where one test is another test's setup?
- How to manage success dependency between unit tests
is a duplicate of the one above.