python - 测试类的 PEP8 命名约定

标签 python class testing pep8

我一直在看PEP 8 -- Style Guide for Python CodePEP8 -- 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/

相关文章:

python - 在 Windows/Python 2.7 上使用 mailer.py 时没有名为 _core 的模块

c++ - 删除主类的对象指针是否也会删除嵌套类指针?

node.js - 在 TFS 上构建想要从 Node.js 测试项目复制可执行文件

python - 使用假设生成具有自定义值限制的列表列表

Python 对列表的插入操作

python - 使用另一个大文件过滤较小的文件

c++ - 为什么不允许在同一个类中定义一个类对象?

testing - 当 web api 仍在 iis 上运行时,如何在内存托管框架中使用组件测试 web api?

python - 如何查找两个 pandas 数据框并从另一个数据框列更新第一个数据框列中的值?

java - 在 Java 运行时尝试从 jar 文件加载类时出现 ClassNotFoundException