Running single test from unittest.TestCase via command line

前端 未结 7 1601
甜味超标
甜味超标 2020-11-28 01:14

In our team, we define most test cases like this:

One \"framework\" class ourtcfw.py:

import unittest

class OurTcFw(unittest.TestCase):         


        
7条回答
  •  抹茶落季
    2020-11-28 01:51

    If you check out the help of the unittest module it tells you about several combinations that allow you to run test case classes from a module and test methods from a test case class.

    python3 -m unittest -h
    
    [...]
    
    Examples:
      python3 -m unittest test_module               - run tests from test_module
      python3 -m unittest module.TestClass          - run tests from module.TestClass
      python3 -m unittest module.Class.test_method  - run specified test method
    

    It does not require you to define a unittest.main() as the default behaviour of your module.

提交回复
热议问题