Re: [Pyunit-interest] feature and usage questions.
Brought to you by:
purcell
From: Stephen P. <ste...@ya...> - 2000-05-17 23:14:40
|
Shae Erisson wrote: > > Yay PyUnit! It's easy to use and it helps me find bugs! > > It's not perfect though :) Admit it, you'd be disappointed if it was. :-) > One thing I'm running across is that NameError (eg. the method doesn't > even exist yet) comes back as a Failure, not as an Error, is this the > correct behaviour? Not quite sure what case you mean. I guessed that you meant the following, which seems to work correctly, so I'm obviously missing something: >>> import unittest >>> >>> class MyTestCase(unittest.TestCase): ... def theTestMethod(self): ... assert 1 ... >>> MyTestCase() Traceback (innermost last): File "<stdin>", line 1, in ? File "unittest.py", line 104, in __init__ raise ValueError,"no such test method: %s" % methodName ValueError: no such test method: runTest >>> MyTestCase('theTestMethod') <__main__.MyTestCase instance at 8108220> ------------- also, >>> import unittest >>> class MyTestCase(unittest.TestCase): ... def checkSomething(self): ... raise NameError, 'oops' ... >>> unittest.TextTestRunner().run(MyTestCase('checkSomething')) .E Time: 0.000s !!!FAILURES!!! Test Results Run: 1 Failures: 0 Errors: 1 There was 1 error: 1) __main__.MyTestCase.checkSomething Traceback (innermost last): File "<stdin>", line 3, in checkSomething NameError: oops <unittest.TextTestResult run=1 errors=1 failures=0> > Also, I'd like to be able merge suites, is there some way to do that? > Right now I have a test_ast.py and a test_brm.py and they both build > suites, I know I can use: > #test_all.py: > import test_ast > ... > suite.addTest(test_ast.ASTTestCase("checkFileLoads")) > suite.addTest(test_brm.BRMTestCase("checkFileLoads")) > but that requires code duplication(yuk) if I want test_brm to be able to > run its own tests by itself. > Any suggestions? Nesting suites within each other is the usual way to accomplish what you want. In this case, I would tend to define an AST suite in test_ast, and a BRM test suite in test_brm. Then, in test_all, I would use import test_ast, test_brm, unittest alltests = unittest.TestSuite() alltests.addSuite(test_ast.suite()) alltests.addSuite(test_brm.suite()) As Michal points out, choosing a naming convention for the 'suite' factory methods may save a little time when you have lots of modules to test: modules_to_test = ('test_ast', 'test_brm', 'test_thg') # and so on alltests = unittest.TestSuite() for module in map(__import__, modules_to_test): alltests.addTest(module.suite()) (didn't try this out, but I think it should work) If you slurp modules_to_test out of a directory listing, you get the kind of functionality that Michal suggests. > I admit, wanting one single report from multiple suites is a case of me > being nitpicky... No, it's a normal requirement. > As for Tk GUI support, what about sticking support for PyUnit into IDLE? That's a thoroughly excellent idea. Haven't got my head enough into (inter?) Tk to offer my services at this point. I'd like to get a good clone of the basic JUnit GUI, but if it could be used with IDLE as well as standalone, that would be wonderful. I started on a GUITestRunner, but didn't get far. One nice feature of JUnit is that all classes are reloaded automatically between test runs, so the GUI need not be restarted constantly. Think it might be more fiddly with Python (hard to believe, but that's my suspicion). -Steve _____________________________________________ Steve Purcell, Technical Director, Inkontact Get in touch at http://www.inkontact.com/ |