简体   繁体   中英

How is the order of test-case invocation chosen by unittest.main()

romantest.py : Dive into Python: Introducing romantest.py

Dive into Python: Test-First 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 am not able to make sense of the invocation order. How is it decided by unittest.main() ?

According to the unittest documentation :

Note that the order in which the various test cases will be run is determined by sorting the test function names with respect to the built-in ordering for strings.

Mostly, you should avoid thinking about the order of tests. You need to write each test so that it is completely independent of the others. Then you don't care about the order of the tests.

Different test runners can run tests in different orders.

As David points out, unittest runs them in order by their function names. I'm not sure what order the test classes are run in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM