How to Return Variable for all tests to use Unittest

Posted by chrissygormley on Stack Overflow See other posts from Stack Overflow or by chrissygormley
Published on 2010-05-26T12:48:00Z Indexed on 2010/05/26 12:51 UTC
Read the original article Hit count: 257

Hello,

I have a Python script and I am trying to set a variable so that if the first test fail's the rest of then will be set to fail. The script I have so far is:

class Tests():

    def function:
        result function..........

    def errorHandle(self):

        return self.error


    def sudsPass(self):

        try:
            result = self.client.service.GetStreamUri(self.stream, self.token)
        except suds.WebFault, e:
            assert False
        except Exception, e:
            pass
        finally:
            if 'result' in locals():
                self.error = True
                self.errorHandle()
                assert True
            else:
                self.error = False
                self.errorHandle()
                assert False  

    def sudsFail(self):

        try:
            result = self.client.service.GetStreamUri(self.stream, self.token)
        except suds.WebFault, e:
            assert False
        except Exception, e:
            pass
        finally:
            if 'result' in locals() or self.error == False:
                assert False
            else:
                assert True   



class GetStreamUri(TestGetStreamUri):

    def runTest(self):

        self.sudsPass()


class GetStreamUriProtocolFail(TestGetStreamUri):

    def runTest(self):

        self.stream.Transport.Protocol = "NoValue"

        self.errorHandle()   
        self.sudsFail()

if __name__ == '__main__':
    unittest.main()

I am trying to get self.error to be set to False if the first test fail. I understand that it is being set in another test but I was hoping someone could help me find a solution to this problem using some other means.

Thanks

PS. Please ignore the strange tests. There is a problem with the error handling at the moment.

© Stack Overflow or respective owner

Related posts about python

Related posts about unit-testing