1

I'm new to python and unittest framework. This might be a very simple question but somehow I couldn't find the answer I need.

I don't want unittest to report total number of testcases base on test* functions in my code. In my case, I have one test_foo function but actually call another function foo() 100 times. So I want to see 'Ran 100 tests in 5.05s' in final report instead of 'Ran 1 test in 5.05s'.

I also don't want to use ddt. So is there a simple way, for example every time when foo() is called, I can update unittest framework to increase the total number of testcase?

mleko
  • 11,650
  • 6
  • 50
  • 71
  • Why do you have one `test_foo` method? You should write one unit test per test case, not one per method. – Platinum Azure Nov 10 '13 at 05:42
  • It looks like you are looking for a way [generate dynamic (parametrized) unit tests in python?][1] [1]: http://stackoverflow.com/questions/32899/how-to-generate-dynamic-parametrized-unit-tests-in-python – Boris Gorelik Nov 10 '13 at 05:45
  • answer platinum, I want to do data driven testing so with one test_foo, I can run multiple tests for different data input. – user2975490 Nov 10 '13 at 06:04
  • bgbg's solution is probably similar to ddt. In my python file I might have test_foo1 (I want to expand it to 100 cases), test_foo2 (I want to expand it to 50 cases) and so on. I will have to put all func generation code in __main__ section which I want to avoid. So doesn't unittest have a function that I can just call to increase total # of test cases? – user2975490 Nov 10 '13 at 06:10
  • @user2975490 you should look into `py.test` it has parameterized testing. – Henrik Andersson Jun 29 '14 at 07:07

0 Answers0