2013-03-31 09:03:40 +08:00
|
|
|
#!/usr/bin/env python
|
2013-06-16 22:15:28 +08:00
|
|
|
"""
|
|
|
|
PyTest-BDD
|
|
|
|
==========
|
|
|
|
|
|
|
|
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:
|
2013-06-16 22:23:42 +08:00
|
|
|
|
|
|
|
.. code:: gherkin
|
2013-06-16 22:15:28 +08:00
|
|
|
|
|
|
|
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:
|
2013-06-16 22:23:42 +08:00
|
|
|
|
2013-06-16 22:15:28 +08:00
|
|
|
.. code:: python
|
|
|
|
|
|
|
|
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
|
|
|
|
````````````
|
|
|
|
|
|
|
|
.. code:: bash
|
|
|
|
|
|
|
|
$ pip install pytest-bdd
|
|
|
|
|
|
|
|
Links
|
|
|
|
`````
|
|
|
|
|
|
|
|
* `website <https://github.com/olegpidsadnyi/pytest-bdd>`_
|
|
|
|
* `documentation <https://pytest-bdd.readthedocs.org/en/latest/>`_
|
|
|
|
|
|
|
|
"""
|
2013-08-10 09:32:25 +08:00
|
|
|
import os
|
2013-05-01 20:03:28 +08:00
|
|
|
import sys
|
2013-04-03 13:57:31 +08:00
|
|
|
|
2013-05-01 20:03:28 +08:00
|
|
|
from setuptools import setup
|
|
|
|
from setuptools.command.test import test as TestCommand
|
2013-04-03 13:57:31 +08:00
|
|
|
|
|
|
|
|
2013-05-01 20:03:28 +08:00
|
|
|
class PyTest(TestCommand):
|
2013-04-03 13:57:31 +08:00
|
|
|
|
|
|
|
def finalize_options(self):
|
2013-05-01 20:03:28 +08:00
|
|
|
TestCommand.finalize_options(self)
|
2013-08-10 09:32:25 +08:00
|
|
|
self.test_args = ['tests', '-pep8', '--cov', 'pytest_bdd', '--cov-report', 'term-missing']
|
2013-05-01 20:03:28 +08:00
|
|
|
self.test_suite = True
|
2013-04-03 13:57:31 +08:00
|
|
|
|
2013-05-01 20:03:28 +08:00
|
|
|
def run_tests(self):
|
2013-08-10 09:32:25 +08:00
|
|
|
# The import is here, cause outside the eggs aren't loaded
|
2013-05-01 20:03:28 +08:00
|
|
|
import pytest
|
|
|
|
errno = pytest.main(self.test_args)
|
|
|
|
sys.exit(errno)
|
2013-03-31 09:03:40 +08:00
|
|
|
|
2013-08-10 09:32:25 +08:00
|
|
|
tests_require = open(os.path.join(os.path.dirname(__file__), 'requirements-testing.txt')).read().split()
|
2013-03-31 09:03:40 +08:00
|
|
|
|
|
|
|
setup(
|
2013-03-31 16:37:53 +08:00
|
|
|
name='pytest-bdd',
|
2013-03-31 09:03:40 +08:00
|
|
|
description='BDD for pytest',
|
2013-06-16 22:15:28 +08:00
|
|
|
long_description=__doc__,
|
2013-04-09 05:30:23 +08:00
|
|
|
author='Oleg Pidsadnyi',
|
2013-06-16 21:52:20 +08:00
|
|
|
license='MIT license',
|
2013-04-10 06:54:38 +08:00
|
|
|
author_email='oleg.podsadny@gmail.com',
|
2013-06-16 22:15:28 +08:00
|
|
|
url='https://github.com/olegpidsadnyi/pytest-bdd',
|
2013-08-10 09:32:25 +08:00
|
|
|
version='0.5.0',
|
2013-06-16 21:52:20 +08:00
|
|
|
classifiers=[
|
|
|
|
'Development Status :: 6 - Mature',
|
|
|
|
'Intended Audience :: Developers',
|
|
|
|
'License :: OSI Approved :: MIT License',
|
|
|
|
'Operating System :: POSIX',
|
|
|
|
'Operating System :: Microsoft :: Windows',
|
|
|
|
'Operating System :: MacOS :: MacOS X',
|
|
|
|
'Topic :: Software Development :: Testing',
|
|
|
|
'Topic :: Software Development :: Libraries',
|
|
|
|
'Topic :: Utilities',
|
|
|
|
'Programming Language :: Python :: 2',
|
|
|
|
'Programming Language :: Python :: 3'
|
|
|
|
] + [('Programming Language :: Python :: %s' % x) for x in '2.6 2.7 3.0 3.1 3.2 3.3'.split()],
|
2013-04-03 13:57:31 +08:00
|
|
|
cmdclass={'test': PyTest},
|
2013-03-31 09:03:40 +08:00
|
|
|
install_requires=[
|
|
|
|
'pytest',
|
|
|
|
],
|
2013-05-28 23:11:47 +08:00
|
|
|
# the following makes a plugin available to py.test
|
2013-06-16 21:52:20 +08:00
|
|
|
entry_points={
|
2013-05-28 23:11:47 +08:00
|
|
|
'pytest11': [
|
|
|
|
'pytest-bdd = pytest_bdd.plugin',
|
|
|
|
]
|
|
|
|
},
|
2013-08-10 09:32:25 +08:00
|
|
|
tests_require=tests_require,
|
2013-04-07 08:24:43 +08:00
|
|
|
packages=['pytest_bdd'],
|
2013-03-31 09:03:40 +08:00
|
|
|
)
|