Best way to assert unit test cases with many conditions
Ganesh Pal
ganesh1pal at gmail.com
Wed Jul 19 03:57:22 EDT 2017
On Tue, Jul 18, 2017 at 11:02 PM, Dan Strohl <D.Strohl at f5.com> wrote:
>
> Like this:
>
> Def test_this(self):
> For i in range(10):
> with self.subTest('test number %s) % i):
> self.assertTrue(I <= 5)
>
> With the subTest() method, if anything within that subTest fails, it won't
> stop the process and will continue with the next step.
>
>
Thanks for reading my email and yes you got it right , I am adding bunch of
same subtest and all are similar and sub test that change only differ in
parameter.
But I can’t use the loop that you have mentioned because I want to achieve
(1) and (2)
(1) I would want my subtest to have a *Condition* based on which it that
would pass my entire test if any of the sub-test passed.
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)
def test_this_1(self):
if Sub_test_1():
#passes then PASS the Complete test i.e. test_this1() and If
sub_test_1() fail then run further subtest!)
elif run sub_test_2() :
#Then PASS test_this_1() 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_1() and don't run next test i.e. sub_test_4
,sub_test_5.. etc)
def test_this_2(self):
if Sub_test_1():
#passes then PASS the Complete test i.e. test_this3() 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)
(1)In general don’t want to fail the test if any sub test fails but
continue with next subtest and PASS the test if any one of fails
(2) Also , I wanted to know if it’s ok Warn and continue , instead of
failing , but I wanted to see if there is assert to warn
29 def test_corruption1(self):
30 """Run test no 1 """
31 #
32
#self.assertTrue(library.log_message_is_reported(self.report,self.blocks['test01']):'''
33 if not library.log_message_is_reported(self.report,
34 self.blocks['test01']):
35 print "Warning: Reporting Failed.... \n"
36
37 if not library.is_corruption_fixed():
38 print "Warning: Corruption is not fixed .... \n"
39
40 if not library.is_corruption_reparied():
41 assert False, "Corruption not reported,fixed and auto
repaired.\n"
42
Let me know if it isn't clear I can give you more examples , Thanks for
responding
Regards,
Ganesh
More information about the Python-list
mailing list