PEP8 naming convention on test classes

前端 未结 2 835
青春惊慌失措
青春惊慌失措 2021-01-01 10:22

I have been looking at PEP 8 -- Style Guide for Python Code and PEP8 -- Advanced Usage for clues on how to name my test classes. However, this is never mentioned on both sit

相关标签:
2条回答
  • 2021-01-01 11:12

    Django and SQLAlchemy, two large, popular Python projects, both use "Name"Test(s). Personally, I prefer that to Test"Name", mainly because when there are multiple TestCases in a file, having each start with "Test" makes scanning difficult.

    Not saying this equals a consensus, only two significant data points and a personal observation.

    0 讨论(0)
  • 2021-01-01 11:19

    The documentation for unittest suggests, e.g.:

    class TestSequenceFunctions(unittest.TestCase):
    
        def test_shuffle(self):
            ...
    
        def test_choice(self):
            ...
    

    commenting

    The three individual tests are defined with methods whose names start with the letters test. This naming convention informs the test runner about which methods represent tests.

    0 讨论(0)
提交回复
热议问题