我一直在看PEP 8 -- Style Guide for Python Code和 PEP8 -- Advanced Usage有关如何命名我的测试类的线索。但是,这两个站点以及我查看过的许多其他站点(例如 Python 文档中的 unittest 页面)都没有提到这一点。我看到的唯一一致的风格是“CapWords”。在 unittest 文档中,他们有 TestSequenceFunctions 和 DefaultWidgetSizeTestCase 的示例。
我想知道是使用“名称”测试还是测试“名称”。方法使用 test_"name"这已经很成熟了。关于类(class),我正在努力寻找一个约定,如果有的话。
感谢论坛对此的帮助。
最佳答案
documentation for unittest
建议,例如:
class TestSequenceFunctions(unittest.TestCase):
def test_shuffle(self):
...
def test_choice(self):
...
评论
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.
关于python - 测试类的 PEP8 命名约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20513596/