Skip to main content

BDD for pytest

Project description

Implements a subset of Gherkin language for the behavior-driven development and automated testing. Benefits from the pytest and its dependency injection pattern for the true just enough specifications and maximal reusability of the BDD definitions.

Example

publish_article.feature:

Scenario: Publishing the article
    Given I'm an author user
    And I have an article
    When I go to the article page
    And I press the publish button
    Then I should not see the error message
    And the article should be published  # Note: will query the database

test_publish_article.py:

from pytest_bdd import scenario, given, when, then

test_publish = scenario('publish_article.feature', 'Publishing the article')


@given('I have an article')
def article(author):
    return create_test_article(author=author)


@when('I go to the article page')
def go_to_article(article, browser):
    browser.visit(urljoin(browser.url, '/manage/articles/{0}/'.format(article.id)))


@when('I press the publish button')
def publish_article(browser):
    browser.find_by_css('button[name=publish]').first.click()


@then('I should not see the error message')
def no_error_message(browser):
    with pytest.raises(ElementDoesNotExist):
        browser.find_by_css('.message.error').first


@then('And the article should be published')
def article_is_published(article):
    article.refresh()  # Refresh the object in the SQLAlchemy session
    assert article.is_published

Installation

$ pip install pytest-bdd

Release history Release notifications

History Node

2.21.0

History Node

2.20.0

History Node

2.19.0

History Node

2.18.2

History Node

2.18.1

History Node

2.18.0

History Node

2.17.1

History Node

2.17.0

History Node

2.16.1

History Node

2.16.0

History Node

2.15.0

History Node

2.14.5

History Node

2.14.4

History Node

2.14.3

History Node

2.14.2

History Node

2.14.1

History Node

2.14.0

History Node

2.13.1

History Node

2.13.0

History Node

2.12.2

History Node

2.12.1

History Node

2.12.0

History Node

2.11.3

History Node

2.11.2

History Node

2.11.1

History Node

2.11.0

History Node

2.10.0

History Node

2.9.1

History Node

2.9.0

History Node

2.8.0

History Node

2.7.2

History Node

2.7.1

History Node

2.7.0

History Node

2.6.2

History Node

2.6.1

History Node

2.6.0

History Node

2.5.3

History Node

2.5.2

History Node

2.5.1

History Node

2.5.0

History Node

2.4.5

History Node

2.4.3

History Node

2.4.2

History Node

2.4.1

History Node

2.4.0

History Node

2.3.3

History Node

2.3.2

History Node

2.3.1

History Node

2.1.1

History Node

2.1.0

History Node

2.0.1

History Node

2.0.0

History Node

0.6.11

History Node

0.6.10

History Node

0.6.9

History Node

0.6.8

History Node

0.6.7

History Node

0.6.6

History Node

0.6.5

History Node

0.6.4

History Node

0.6.3

History Node

0.6.2

History Node

0.6.1

History Node

0.6.0

History Node

0.5.2

History Node

0.5.1

History Node

0.5.0

History Node

0.4.7

History Node

0.4.6

History Node

0.4.5

This version
History Node

0.4.3

History Node

0.4.2

History Node

0.4.1

History Node

0.4

History Node

0.3

History Node

0.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
pytest-bdd-0.4.3.tar.gz (7.0 kB) Copy SHA256 hash SHA256 Source None Jun 16, 2013

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page