PEP8测试类的命名约定 [英] PEP8 naming convention on test classes

查看:88
本文介绍了PEP8测试类的命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在查看 PEP 8-Python代码样式指南 PEP8-高级用法,以获取有关如何命名测试类的线索。但是,这两个网站以及我浏览过的许多其他网站都从未提及过,例如Python文档中的unittest页面。我看到的唯一一致的样式是 CapWords。在单元测试文档中,他们有TestSequenceFunctions以及DefaultWidgetSizeTestCase的示例。

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 sites, as well as many other sites I have looked at, such as the unittest page in the Python documentation. The only consistent style I see is "CapWords". In the unittest documentation they have examples for TestSequenceFunctions as well as DefaultWidgetSizeTestCase.

我试图找出的是使用 Name Test还是Test Name。方法使用test_ name,这已经很确定了。关于类,我正在努力寻找是否有一个约定。

What I am trying to find out is whether to use "Name"Test or Test"Name". Methods use test_"name" and that's pretty much established. With regards to classes I am struggling to find a convention if there's one.

非常感谢论坛对此提供的帮助。

Would appreciate the forum's help on this.

推荐答案

unittest 建议,例如:

The documentation for unittest suggests, e.g.:

class TestSequenceFunctions(unittest.TestCase):

    def test_shuffle(self):
        ...

    def test_choice(self):
        ...

评论


三个人测试用名称以字母 test 开头的方法定义。此命名约定将告知测试运行者哪些方法表示测试。

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.

这篇关于PEP8测试类的命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆