1

Possible Duplicate:
Python unittest - invoke unittest.main() with a custom TestSuite

I have a testsuite created with e.g.

suite = unittest.TestSuite()
suite.addTest(module1.MyTest("test_simple"))
suite.addTest(module2.MyTest("test_simple"))

and need to start these tests with unitest.main(). When trying just unitest.main(suite) no tests are run at all. How can I do this with unittest.main() without calling test.TextTestRunner or similar?

Community
  • 1
  • 1
Alex
  • 41,580
  • 88
  • 260
  • 469
  • 1
    You need a runner to run tests. Why don't you want to use one? – Piotr Dobrogost Nov 12 '12 at 11:49
  • I do not need a runner, when I create a single TestCase in a code and call unittest.main(). – Alex Nov 12 '12 at 11:52
  • @Piotr No its not a duplicate. The question in the given link is similar, but has never been answered (correctly). Or maybe I do not understand the answer. – Alex Nov 12 '12 at 12:05
  • The fact it hasn't been answered does not change the fact the two ask about the same. – Piotr Dobrogost Nov 12 '12 at 12:16
  • Agreed. But the fact that the question is about the same does not change the fact that it is still not answered. – Alex Nov 12 '12 at 12:18

1 Answers1

3

You can't pass a TestSuite to main, check out the constructor of unittest.main.TestProgram (which is was unittest.main actually is) and how this class works. The first argument if anything is the module name, not a testsuite.

main() actually takes its arguments from sys.argv, as it is actually intended to be used from the command line and not from within a program. It's just common to do so for convenience.

mata
  • 67,110
  • 10
  • 163
  • 162