views:

62

answers:

1

I'm making unittests with python. I am not using any automatical test discovery. I am assembling TestCases into a TestSuite manually.

I can run these tests with unittest.TextTestRunner().run(suite), I would like to run them with unittest.main() so that I can use command line options (like -v/--failfast). The documentation says that unittest.main() can take a TestRunner option.

How to convert my TestSuite into a TestRunner?

A: 

Do nothing except be sure you have this in your unit test module.

if __name__ == '__main__':
    unittest.main(failfast=True)

http://docs.python.org/library/unittest.html#unittest.main

From the documentation...

unittest.main( failfast=True, testRunner=unittest.TextTestRunner )
S.Lott
I am not using unittest.main()'s test autodiscovery, I am hand crafting a TestSuite. If I use unittest.main as you suggest it won't run my tests. I've tried.
Rory
Why hand-cract? Why won't main autodiscover your tests? What are your test superclasses? What are your test names? It works perfectly for me. What are you doing wrong?
S.Lott
I am not using autodiscover because I am making TestCases based on known valid inputs for a function. I am using this approach http://stackoverflow.com/questions/2798956/python-unittest-generate-multiple-tests-programmatically/3772008#3772008
Rory
@Rory: That approach seems silly. Why not put the loop in `runTest` where it's supposed to be? Why create a complex suite when you could move the complexity into one test case that simply iterates through the values?
S.Lott
@S.Lott see the benefits I listed in that answer.
Rory
@Rory: I did see those "benefits". I don't agree with them. They aren't "beneficial". This question -- indeed -- is evidence that it's actually harmful, not helpful.
S.Lott