Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'method.': 0.05; 'url:pipermail': 0.05; 'run,': 0.07; 'unittest': 0.07; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'static': 0.13; 'cases': 0.15; 'above?': 0.16; 'doc,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'sorting': 0.16; 'subject:run': 0.16; 'subject:unittest': 0.16; 'wrote:': 0.17; 'thanks,': 0.18; 'tests': 0.18; 'sort': 0.21; 'fairly': 0.21; 'kevin': 0.23; 'statement': 0.23; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.28; 'this?': 0.28; 'run': 0.28; 'function': 0.30; 'url:python': 0.32; 'defining': 0.33; 'to:addr :python-list': 0.33; 'built-in': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'test': 0.36; 'one,': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'build': 0.39; 'header:Received:5': 0.40; 'url:mail': 0.40; 'think': 0.40; 'respect': 0.63; 'skip:n 10': 0.63; 'zhang': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: unittest - sort cases to be run Date: Tue, 21 Aug 2012 20:00:26 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p508492ad.dip.t-dialin.net User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345572043 news.xs4all.nl 6904 [2001:888:2000:d::a6]:50524 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27590 Kevin Zhang wrote: > I want to sort the order of the unittest cases to be run, but found such > statement in Python doc, > "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." > > s.addTest(BTest()) > s.addTest(ATest()) > TextTestRunner().run(ts) > > I need BTest() to be run prior to ATest(), is there any natural/beautiful > way to achieve this? Thanks, Did you try the above? I think BTest *will* run before ATest. The sorting is performed by the TestLoader if there is one, i. e. if you don't build a test suite manually. If you *do* use a TestLoader you can still influence the sort order by defining a sortTestMethodsUsing static method. Here's a fairly complex example: [Ordering tests in a testsuite] http://mail.python.org/pipermail/python-list/2010-October/589058.html