【问题标题】:How to organise pytest cases using pytest-describe plugin如何使用 pytest-describe 插件组织 pytest 用例
【发布时间】:2023-01-27 05:25:32
【问题描述】:

有没有人有关于如何使用 describe 插件运行 pytest 的示例。我正在寻找使用任意嵌套块来安排我的 pytests。这个插件似乎可以做到这一点,但我没有看到任何示例。有人可以帮忙吗?

阿比吉特

【问题讨论】:

    标签: pytest


    【解决方案1】:

    describe blocks come from rspec,这个答案是由它在 rspec 中的完成方式决定的。

    使用 rspec 编写测试时的一个常见模式是按类组织,然后按方法组织。测试名称应描述上下文和预期行为。

    def describe_cat():
      def describe_eat():
        def it_randomly_wont_eat():
        def with_tuna_it_will_always_eat():
    

    如果您正在编写函数,请为每个函数执行一个描述块。

    def describe_something():
      def with_no_arguments_it_uses_defaults():
      def it_validates_the_name():
    

    这种模式既有助于组织代码,又避免了巨大的单体文件。它确保您正在编写单元测试;每个测试测试一件事。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-19
      • 1970-01-01
      • 2021-11-30
      • 1970-01-01
      • 1970-01-01
      • 2020-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多