I have 4 modules. 1. run.py Here I'm doing initialization and setup of class A and Class B. And what I want to do is:
try:
x = x[0]()
except TestFailure as tf:
print tf.message
where due to for loop, x iterates over class A and Class B. Hence for first iteration, 1st it's doing initialization for class A and then it's doing it for B.
Test.py Here I've class Test
class Test(object): IS_TEST = False teardown_stack = [] td=[] def __init__(self): print "in Test init" super(Test, self).__init__() def setup(self): print "\tin Test setup" #self.add_teardown(foo)
and now
class TestFailure (None, msg):
message = ""
if self.msg:
message = self.msg
pass
I have A.py
class A(Test): IS_TEST = True def __init__(self): test_variable = 9; if test_variable < 0: raise TestFailure("test_variable is negative.") print "in A init" super(A, self).__init__() def setup(self): print "in A setup"
and last module I have is B.py
class B(A): IS_TEST = True def __init__(self): test_variable = 9; if test_variable < 0: raise TestFailure("test_variable is negative.") print "in B init" super(B, self).__init__() def setup(self): print "\tin B setup"
I haven't used python exceptions before and hence I'm not familiar with them at all. How to get this work? Where exactly I'm going wrong? I want to raise exception by this method where before doing initialization, it makes the operation happen only when test_variable is positive.