Re: [Pyunit-interest] testing order of classes in a module
Brought to you by:
purcell
From: Steve P. <ste...@ya...> - 2003-01-12 10:50:38
|
On Saturday 11 January 2003 09:35, Andrew Dalke wrote: > I'm writing an interface to a web service. Because each request > takes a while (a couple of second) I wrote a wrapper which > catches all calls and results and saves them to a file. In that > way I can run my unit tests against the file, which is much > faster. (I retest against the main server too, but not as often.) > > The server is stateful, so I must do the same calls in the same > order. I assumed the order the tests were executed in a module > are always the same, so I simply pickled all socket input and > output to a file, expecting I could read the picked data out > in the same order it was put in. Hi Andrew, The framework relies on the test author making sure that individual test case do not interfere with each other's results. In your case, sorting the test cases by class name solves the problem, but I think the real difficulty is how you have defined the tests. If your current test cases interfere with each other due to the stateful nature of the server, you should probably do one of the following things. Firstly, you could arrange that the server is reset after every test case by overriding the 'tearDown()' method of TestCase. Or secondly, you could merge interdependent test cases into single test cases, such that they run together. ie. assuming you have two interdependent test cases: class MyFirstTestCase(unittest.TestCase): def testFirstThing(self): tryFirstThing() class MySecondTestCase(unittest.TestCase): def testSecondThing(self): trySecondThing() instead arrange the test code like this: class MyCombinedTestCase(unittest.TestCase): def testCombinedThing(self): tryFirstThing() trySecondThing() Hope that helps, -Steve -- Steve Purcell http://advogato.org/person/purcell |