【发布时间】:2023-01-27 05:25:32
【问题描述】:
有没有人有关于如何使用 describe 插件运行 pytest 的示例。我正在寻找使用任意嵌套块来安排我的 pytests。这个插件似乎可以做到这一点,但我没有看到任何示例。有人可以帮忙吗?
阿比吉特
【问题讨论】:
标签: pytest
有没有人有关于如何使用 describe 插件运行 pytest 的示例。我正在寻找使用任意嵌套块来安排我的 pytests。这个插件似乎可以做到这一点,但我没有看到任何示例。有人可以帮忙吗?
阿比吉特
【问题讨论】:
标签: pytest
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():
这种模式既有助于组织代码,又避免了巨大的单体文件。它确保您正在编写单元测试;每个测试测试一件事。
【讨论】: