Python unittest philosophy and sequencing

While the philosophy of unittesting is that tests can be run in any order and that should pass, what if you implement an API where there is no other means of communicating with the server ... and you need to test certain very simple function (for example , deletion) before you can perform more complex tasks? Is ordering tests then reasonable?

If so, how can I do this using the python module unittest

?

+3


source to share


1 answer


You seem to understand that your unit tests should be independent. The only reason I can see that you want to run the tests in a specific order is because you want to stop running the package if early testing failed. For this you can use the command line option

-f, --failfast

      

Stop the test run on the first error or error.

By the way, tests are performed in alphabetical order:



the order in which the various test cases will run is determined by sorting the test function names with respect to the inline ordering for strings.

( docs )

0


source







All Articles