Python, unit test - Pass command line arguments to setUp of unittest.TestCase

前端 未结 4 1459
情书的邮戳
情书的邮戳 2020-12-08 03:02

I have a script that acts as a wrapper for some unit tests written using the Python unittest module. In addition to cleaning up some files, creating an output s

4条回答
  •  误落风尘
    2020-12-08 03:07

    If you define the attributes in the init method, then you can simply pass them all in the constructor like this..

    import unittest
    import helpspot
    
    class TestHelpSpot(unittest.TestCase):
        "A few simple tests for HelpSpot"
    
        def __init__(self, testname, path, user, pword):
            super(TestHelpSpot, self).__init__(testname)
            self.path = path
            self.user = user
            self.pword = pword
    ....
    ....
    ....
    
    
    if __name__ == '__main__':
        True
    
        suite = unittest.TestSuite()
        suite.addTest(TestHelpSpot("test_version", path, user, pword))    
    
        unittest.TextTestRunner().run(suite)
    

提交回复
热议问题