How do I run multiple Classes in a single test suite in Python using unit testing?

后端 未结 5 930
无人共我
无人共我 2021-02-01 03:09

How do I run multiple Classes in a single test suite in Python using unit testing?

5条回答
  •  醉梦人生
    2021-02-01 03:29

    I'm a bit unsure at what you're asking here, but if you want to know how to test multiple classes in the same suite, usually you just create multiple testclasses in the same python file and run them together:

    import unittest
    
    class TestSomeClass(unittest.TestCase):
        def testStuff(self):
                # your testcode here
                pass
    
    class TestSomeOtherClass(unittest.TestCase):
        def testOtherStuff(self):
                # testcode of second class here
                pass
    
    if __name__ == '__main__':
        unittest.main()
    

    And run with for example:

    python mytestsuite.py
    

    Better examples can be found in the official documention.

    If on the other hand you want to run multiple test files, as detailed in "How to organize python test in a way that I can run all tests in a single command?", then the other answer is probably better.

提交回复
热议问题