python - 生菜、 Django 的背景

标签 python django unit-testing bdd lettuce

我如何在生菜测试(django)中编写背景,背景在每个场景之前运行, 在 cucumber 中我可以写这样的背景:

Feature: Multiple site support
  As a Mephisto site owner
  I want to host blogs for different people
  In order to make gigantic piles of money

  Background:
    Given a global administrator named "Greg"
    And a blog named "Greg's anti-tax rants"
    And a customer named "Dr. Bill"
    And a blog named "Expensive Therapy" owned by "Dr. Bill"

  Scenario: Dr. Bill posts to his own blog
    Given I am logged in as Dr. Bill
    When I try to post to "Expensive Therapy"
    Then I should see "Your article was published."

  Scenario: Dr. Bill tries to post to somebody else's blog, and fails
    Given I am logged in as Dr. Bill
    When I try to post to "Greg's anti-tax rants"
    Then I should see "Hey! That's not your blog!"

最佳答案

您可以在生菜中使用背景,例如(取自 here ):

Feature: Simple and successful
  As the Lettuce maintainer
  In order to make sure the output is pretty
  I want to automate its test

  Background:
    Given the variable "X" holds 2

  Scenario: multiplication changing the value
    Given the variable "X" is equal to 2

关于python - 生菜、 Django 的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18524915/

相关文章:

python - sqlite3.操作错误: database is locked

python - 通过子进程将python的文件之类的对象传递给ffmpeg

Django modelformset_factory() 过滤

python - 字段错误: Cannot resolve 'publish_year' into field

javascript - 监视 jasmine 中的 jquery ui 小部件

c# - 用于测试调用异步方法的 ICommand 的模式

python - 如何使用 `fixture` 和 `parametrize` 为 pytest 测试设置环境变量

python - Pandas read_sql 函数生成二进制列名

python - 预分配一个无列表

java - 不能使模拟的单例方法在不同的测试用例中表现不同