Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 954
Amandasaurus Avatar asked Nov 26 '22 17:11

Amandasaurus


1 Answers

Near duplicate of How to run a testsuite with unittest.main (answer copy-and-pasted):

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.

like image 197
Alex Avatar answered Jan 02 '23 23:01

Alex