As the order of the test case invocation, unittest.main () is selected

romantest.py : Immersion in Python: introducing romantest.py

Immersion in Python: test programming -

 $ python romantest.py -v fromRoman should only accept uppercase input ... ERROR toRoman should always return uppercase ... ERROR fromRoman should fail with malformed antecedents ... FAIL fromRoman should fail with repeated pairs of numerals ... FAIL fromRoman should fail with too many repeated numerals ... FAIL fromRoman should give known result with known input ... FAIL toRoman should give known result with known input ... FAIL fromRoman(toRoman(n))==n for all n ... FAIL toRoman should fail with non-integer input ... FAIL toRoman should fail with negative input ... FAIL toRoman should fail with large input ... FAIL toRoman should fail with 0 input ... FAIL [... snipped ...] 

I can not understand the order of the call. How is this accepted in unittest.main() ?

+4
source share
2 answers

According to unittest documentation :

Note that the order in which various test cases will be executed is determined by sorting the names of the test functions relative to the built-in ordering for the strings.

+3
source

Basically, you should avoid thinking about the test order. You need to write each test so that it is completely independent of the others. Then you do not need to monitor the order of the tests.

Different test videos can run tests in different orders.

As David points out, unittest runs them in order by the names of their functions. I am not sure in what order the test classes run.

+2
source

All Articles