[Pyunit-interest] Using re to describe test methods to test
Brought to you by:
purcell
From: Dinu G. <gh...@da...> - 2001-03-26 08:57:10
|
Hello, while developping test suites I found myself quite often writing code like this: suite.addTest(TestClassA('test1')) suite.addTest(TestClassA('test2')) suite.addTest(TestClassB('test1')) suite.addTest(TestClassB('test2')) suite.addTest(TestClassC('test1')) suite.addTest(TestClassC('test2')) suite.addTest(TestClassC('test3')) Because I was spending an increasing amount of time editing the list above, commenting lines and uncommenting them again, one day I began using regular expressions to describe what methods I really wanted tested and found this to save quite some time again. I've attached a module showing in full action what I mean, working partly on itself as a test case. In fact, I have tried to bind the getTestMethodNames function to some test classes as a class method, but found that to be conflicting either with the unittest module or my brain, so I dropped that again (but it's not really necessary to do that any- way). I'm not sure if this is also useful for other folks here, but in any case you may give it a try and/or Steve might want to think about if or not it would make sense to add something like this to the package itself. In that case it might look like this, perhaps: suite.addTests(TestClassC('test\d+')) Regards, Dinu -- Dinu C. Gherman ReportLab Consultant - http://www.reportlab.com ................................................................ "The only possible values [for quality] are 'excellent' and 'in- sanely excellent', depending on whether lives are at stake or not. Otherwise you don't enjoy your work, you don't work well, and the project goes down the drain." (Kent Beck, "Extreme Programming Explained") |