Best way to assert unit test cases with many conditions

Rob Gaddi rgaddi at highlandtechnology.invalid
Wed Jul 19 14:14:51 EDT 2017


On 07/19/2017 03:26 AM, Ganesh Pal wrote:
>>
>> Yes.  Just assert each thing as it needs asserting.
>>
>>
>   Asserting each sub test will fail the entire test,  I want the  to pass
> the test if any the sub test passes.  If the sub test fail try all cases
> and fail for the last one.
> 
> Example :
> 
> 
> 
> def test_this(self):
> 
>        if Sub_test_1():
> 
>      #passes  then  PASS the  Complete test  i.e. test_this() and  If
> sub_test_1() fail then run further subtest!)
> 
>       elif run sub_test_2() :
> 
>       #Then PASS test_this() and  don't run  next test i.e
> sub_test_3(),sub_test_4() etc)
> 
>       elif run sub_test_3()
> 
>       if sub_test_3()
> 
>       #  Then pass  test_this() and  don't run next test  i.e. sub_test_4()
> ,sub_test_5(). etc)
> 
> 
> 
> Regards,
> 
> Ganesh
> 

So you're saying if test 1 passes you don't even bother to run test 2? 
To be blunt, that sounds convoluted and overcomplicated.  How would you 
ever know that test2 is even doing its job?

Why is this superior to writing five tests, all of which always run? 
Note that "runtime" is not a valid answer unless you're talking about 
multiple minutes of it.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.



More information about the Python-list mailing list