我想创建一个名为BasicTest的python的unittest.Testcase的子类我希望BasicTest的每个子类在main中运行相同的例程我怎样才能做到这一点?
例子:
in basic_test.py:
class BasicTest(unittest.TestCase):
...
if __name__ == '__main__':
# Do optparse stuff
unittest.main()
in some_basic_test.py:
class SomeBasicTest(BasicTest):
...
if __name__ == '__main__':
#call the main in basic_test.py
最佳答案
# basic_test.py
class BasicTest(unittest.TestCase):
@staticmethod
def main():
# Do optparse stuff
unittest.main()
if __name__ == '__main__':
BasicTest.main()
# some_basic_test.py
class SomeBasicTest(BasicTest):
...
if __name__ == '__main__':
BasicTest.main()