[Python-modules-commits] [pytest-bdd] 01/02: import pytest-bdd-2.18.2.tar.gz
Brian May
bam at moszumanska.debian.org
Tue May 16 08:02:21 UTC 2017
This is an automated email from the git hooks/post-receive script.
bam pushed a commit to branch debian/master
in repository pytest-bdd.
commit 5b4f677f7b9eee4aee008104bbf1f384fcd7a112
Author: Brian May <brian at linuxpenguins.xyz>
Date: Tue May 16 08:08:23 2017 +1000
import pytest-bdd-2.18.2.tar.gz
---
.gitignore | 55 +
.travis.yml | 21 +
AUTHORS.rst | 22 +
CHANGES.rst | 339 ++++++
LICENSE.txt | 7 +
MANIFEST.in | 4 +
Makefile | 23 +
README.rst | 1242 ++++++++++++++++++++
docs/Makefile | 153 +++
docs/conf.py | 245 ++++
docs/index.rst | 10 +
pytest_bdd/__init__.py | 8 +
pytest_bdd/cucumber_json.py | 160 +++
pytest_bdd/exceptions.py | 74 ++
pytest_bdd/feature.py | 562 +++++++++
pytest_bdd/fixtures.py | 17 +
pytest_bdd/generation.py | 195 +++
pytest_bdd/gherkin_terminal_reporter.py | 98 ++
pytest_bdd/hooks.py | 45 +
pytest_bdd/parsers.py | 130 ++
pytest_bdd/plugin.py | 84 ++
pytest_bdd/reporting.py | 175 +++
pytest_bdd/scenario.py | 391 ++++++
pytest_bdd/scripts.py | 79 ++
pytest_bdd/steps.py | 325 +++++
pytest_bdd/templates/test.py.mak | 29 +
pytest_bdd/types.py | 17 +
pytest_bdd/utils.py | 74 ++
requirements-testing.txt | 5 +
setup.cfg | 3 +
setup.py | 93 ++
tests/__init__.py | 0
tests/args/__init__.py | 0
tests/args/args_steps.feature | 10 +
tests/args/cfparse/__init__.py | 0
tests/args/cfparse/test_args.py | 75 ++
tests/args/conftest.py | 8 +
tests/args/parse/__init__.py | 0
tests/args/parse/test_args.py | 75 ++
tests/args/regex/__init__.py | 0
tests/args/regex/test_args.py | 77 ++
tests/args/subfolder/__init__.py | 0
tests/args/subfolder/args.feature | 8 +
tests/args/subfolder/test_args.py | 42 +
tests/args/test_arg_fixture_mix.py | 93 ++
tests/args/when_arguments.feature | 14 +
tests/conftest.py | 16 +
tests/feature/__init__.py | 0
tests/feature/alias.feature | 9 +
tests/feature/background.feature | 18 +
tests/feature/comments.feature | 8 +
tests/feature/conftest.py | 11 +
tests/feature/description.feature | 12 +
tests/feature/gherkin_terminal_reporter.feature | 42 +
tests/feature/given_after_then.feature | 5 +
tests/feature/given_after_when.feature | 4 +
tests/feature/multiline.feature | 7 +
.../feature/no_sctrict_gherkin_background.feature | 8 +
tests/feature/no_sctrict_gherkin_scenario.feature | 6 +
tests/feature/not_found.feature | 4 +
tests/feature/outline.feature | 62 +
tests/feature/outline_feature.feature | 16 +
tests/feature/parametrized.feature | 4 +
tests/feature/reuse.feature | 8 +
tests/feature/same_function_name.feature | 3 +
tests/feature/steps.feature | 33 +
tests/feature/tags.feature | 10 +
tests/feature/test_alias.py | 31 +
tests/feature/test_background.py | 78 ++
tests/feature/test_cucumber_json.py | 175 +++
tests/feature/test_description.py | 21 +
tests/feature/test_feature_base_dir.py | 25 +
tests/feature/test_gherkin_terminal_reporter.py | 278 +++++
tests/feature/test_multiline.py | 99 ++
tests/feature/test_no_scenario.py | 48 +
tests/feature/test_no_sctrict_gherkin.py | 59 +
tests/feature/test_outline.py | 196 +++
tests/feature/test_parametrized.py | 47 +
tests/feature/test_report.py | 258 ++++
tests/feature/test_reuse.py | 34 +
tests/feature/test_same_function_name.py | 16 +
tests/feature/test_scenario.py | 67 ++
tests/feature/test_scenarios.py | 63 +
tests/feature/test_steps.py | 260 ++++
tests/feature/test_tags.py | 214 ++++
tests/feature/test_wrong.py | 105 ++
tests/feature/then_first.feature | 2 +
tests/feature/when_after_then.feature | 6 +
tests/feature/when_in_background.feature | 10 +
tests/feature/wrong_multiple_features.feature | 23 +
tests/feature/wrong_type_order.feature | 24 +
tests/generation/__init__.py | 0
tests/generation/generation.feature | 15 +
tests/generation/test_generate_missing.py | 59 +
tests/library/__init__.py | 0
tests/library/child/__init__.py | 0
tests/library/child/conftest.py | 6 +
tests/library/child/test_local_override.py | 37 +
tests/library/child/test_parent_override.py | 14 +
tests/library/conftest.py | 11 +
tests/library/test_parent.py | 20 +
tests/scripts/__init__.py | 0
tests/scripts/generate.feature | 9 +
tests/scripts/test_generate.py | 52 +
tests/scripts/test_main.py | 17 +
tests/scripts/test_migrate.py | 39 +
tests/steps/__init__.py | 0
tests/steps/given.feature | 18 +
tests/steps/test_given.py | 71 ++
tests/steps/test_steps.py | 43 +
tests/steps/test_unicode.py | 59 +
tests/steps/unicode.feature | 9 +
tests/test_hooks.py | 32 +
tox.ini | 42 +
114 files changed, 8065 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3eadcb4
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,55 @@
+*.rej
+*.py[cod]
+/.env
+*.orig
+
+# C extensions
+*.so
+
+# Packages
+*.egg
+*.egg-info
+dist
+build
+_build
+eggs
+parts
+bin
+var
+sdist
+develop-eggs
+.installed.cfg
+lib
+lib64
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+nosetests.xml
+
+# Translations
+*.mo
+
+# Mr Developer
+.mr.developer.cfg
+.project
+.pydevproject
+.cache
+.ropeproject
+
+# Sublime
+/*.sublime-*
+
+#PyCharm
+/.idea
+
+# virtualenv
+/.Python
+/lib
+/include
+/src
+/share
+/local
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..4559d30
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,21 @@
+sudo: false
+language: python
+python: "3.4"
+env:
+ matrix:
+ - TESTENV=linters
+ - TESTENV=py27
+# - TESTENV=py27-xdist
+ - TESTENV=py27-pytest-latest
+ - TESTENV=py34
+ - TESTENV=coveralls
+install:
+ - pip install tox
+script: tox -e $TESTENV --recreate
+branches:
+ except:
+ - /^\d/
+notifications:
+ email:
+ - bubenkoff at gmail.com
+ - oleg.pidsadnyi at gmail.com
diff --git a/AUTHORS.rst b/AUTHORS.rst
new file mode 100644
index 0000000..aae000b
--- /dev/null
+++ b/AUTHORS.rst
@@ -0,0 +1,22 @@
+Authors
+=======
+
+`Oleg Pidsadnyi <oleg.pidsadnyi at gmail.com>`_
+ original idea, initial implementation and further improvements
+`Anatoly Bubenkov <bubenkoff at gmail.com>`_
+ key implementation idea and realization, many new features and improvements
+
+These people have contributed to `pytest-bdd`, in alphabetical order:
+
+* `Adam Coddington <me at adamcoddington.net>`_
+* `Albert-Jan Nijburg <albertjan at curit.com>`_
+* `Andrey Makhnach <andrey.makhnach at gmail.com>`_
+* `Aron Curzon <curzona at gmail.com>`_
+* `Dmitrijs Milajevs <dimazest at gmail.com>`_
+* `Florian Bruhin <me at the-compiler.org>`_
+* `Floris Bruynooghe <flub at devork.be>`_
+* `Harro van der Klauw <hvdklauw at gmail.com>`_
+* `Laurence Rowe <l at lrowe.co.uk>`_
+* `Leonardo Santagada <santagada at github.com>`_
+* `Robin Pedersen <ropez at github.com>`_
+* `Sergey Kraynev <sergejyit at gmail.com>`_
diff --git a/CHANGES.rst b/CHANGES.rst
new file mode 100644
index 0000000..c1cf0a7
--- /dev/null
+++ b/CHANGES.rst
@@ -0,0 +1,339 @@
+Changelog
+=========
+
+2.18.2
+------
+
+- Fix check for out section steps definitions for no strict gherkin feature
+
+2.18.1
+------
+
+- Relay fixture results to recursive call of 'get_features' (coddingtonbear)
+
+2.18.0
+------
+
+- Add gherkin terminal reporter (spinus + thedrow)
+
+2.17.2
+------
+
+- Fix scenario lines containing an ``@`` being parsed as a tag. (The-Compiler)
+
+2.17.1
+------
+
+- Add support for pytest 3.0
+
+2.17.0
+------
+
+- Fix FixtureDef signature for newer pytest versions (The-Compiler)
+- Better error explanation for the steps defined outside of scenarios (olegpidsadnyi)
+- Add a ``pytest_bdd_apply_tag`` hook to customize handling of tags (The-Compiler)
+- Allow spaces in tag names. This can be useful when using the
+ ``pytest_bdd_apply_tag`` hook with tags like ``@xfail: Some reason``.
+
+
+2.16.1
+------
+
+- Cleaned up hooks of the plugin (olegpidsadnyi)
+- Fixed report serialization (olegpidsadnyi)
+
+
+2.16.0
+------
+
+- Fixed deprecation warnings with pytest 2.8 (The-Compiler)
+- Fixed deprecation warnings with Python 3.5 (The-Compiler)
+
+2.15.0
+------
+
+- Add examples data in the scenario report (bubenkoff)
+
+2.14.5
+------
+
+- Properly parse feature description (bubenkoff)
+
+2.14.3
+------
+
+- Avoid potentially random collection order for xdist compartibility (bubenkoff)
+
+2.14.1
+------
+
+- Pass additional arguments to parsers (bubenkoff)
+
+2.14.0
+------
+
+- Add validation check which prevents having multiple features in a single feature file (bubenkoff)
+
+2.13.1
+------
+
+- Allow mixing feature example table with scenario example table (bubenkoff, olegpidsadnyi)
+
+2.13.0
+------
+
+- Feature example table (bubenkoff, sureshvv)
+
+2.12.2
+------
+
+- Make it possible to relax strict Gherkin scenario validation (bubenkoff)
+
+2.11.3
+------
+
+- Fix minimal `six` version (bubenkoff, dustinfarris)
+
+2.11.1
+------
+
+- Mention step type on step definition not found errors and in code generation (bubenkoff, lrowe)
+
+2.11.0
+------
+
+- Prefix step definition fixture names to avoid name collisions (bubenkoff, lrowe)
+
+2.10.0
+------
+
+- Make feature and scenario tags to be fully compartible with pytest markers (bubenkoff, kevinastone)
+
+2.9.1
+-----
+
+- Fixed FeatureError string representation to correctly support python3 (bubenkoff, lrowe)
+
+2.9.0
+-----
+
+- Added possibility to inject fixtures from given keywords (bubenkoff)
+
+2.8.0
+-----
+
+- Added hook before the step is executed with evaluated parameters (olegpidsadnyi)
+
+2.7.2
+-----
+
+- Correct base feature path lookup for python3 (bubenkoff)
+
+2.7.1
+-----
+
+- Allow to pass ``scope`` for ``given`` steps (bubenkoff, sureshvv)
+
+2.7.0
+-----
+
+- Implemented `scenarios` shortcut to automatically bind scenarios to tests (bubenkoff)
+
+2.6.2
+-----
+
+- Parse comments only in the begining of words (santagada)
+
+2.6.1
+-----
+
+- Correctly handle `pytest-bdd` command called without the subcommand under python3 (bubenkoff, spinus)
+- Pluggable parsers for step definitions (bubenkoff, spinus)
+
+2.5.3
+-----
+
+- Add after scenario hook, document both before and after scenario hooks (bubenkoff)
+
+2.5.2
+-----
+
+- Fix code generation steps ordering (bubenkoff)
+
+2.5.1
+-----
+
+- Fix error report serialization (olegpidsadnyi)
+
+2.5.0
+-----
+
+- Fix multiline steps in the Background section (bubenkoff, arpe)
+- Code cleanup (olegpidsadnyi)
+
+
+2.4.5
+-----
+
+- Fix unicode issue with scenario name (bubenkoff, aohontsev)
+
+2.4.3
+-----
+
+- Fix unicode regex argumented steps issue (bubenkoff, aohontsev)
+- Fix steps timings in the json reporting (bubenkoff)
+
+2.4.2
+-----
+
+- Recursion is fixed for the --generate-missing and the --feature parameters (bubenkoff)
+
+2.4.1
+-----
+
+- Better reporting of a not found scenario (bubenkoff)
+- Simple test code generation implemented (bubenkoff)
+- Correct timing values for cucumber json reporting (bubenkoff)
+- Validation/generation helpers (bubenkoff)
+
+2.4.0
+-----
+
+- Background support added (bubenkoff)
+- Fixed double collection of the conftest files if scenario decorator is used (ropez, bubenkoff)
+
+2.3.3
+-----
+
+- Added timings to the cucumber json report (bubenkoff)
+
+2.3.2
+-----
+
+- Fixed incorrect error message using e.argname instead of step.name (hvdklauw)
+
+2.3.1
+-----
+
+- Implemented cucumber tags support (bubenkoff)
+- Implemented cucumber json formatter (bubenkoff, albertjan)
+- Added 'trace' keyword (bubenkoff)
+
+2.1.2
+-----
+
+- Latest pytest compartibility fixes (bubenkoff)
+
+2.1.1
+-----
+
+- Bugfixes (bubenkoff)
+
+2.1.0
+-----
+
+- Implemented multiline steps (bubenkoff)
+
+2.0.1
+-----
+
+- Allow more than one parameter per step (bubenkoff)
+- Allow empty example values (bubenkoff)
+
+2.0.0
+-----
+
+- Pure pytest parametrization for scenario outlines (bubenkoff)
+- Argumented steps now support converters (transformations) (bubenkoff)
+- scenario supports only decorator form (bubenkoff)
+- Code generation refactoring and cleanup (bubenkoff)
+
+1.0.0
+-----
+
+- Implemented scenario outlines (bubenkoff)
+
+
+0.6.11
+------
+
+- Fixed step arguments conflict with the fixtures having the same name (olegpidsadnyi)
+
+0.6.9
+-----
+
+- Implemented support of Gherkin "Feature:" (olegpidsadnyi)
+
+0.6.8
+-----
+
+- Implemented several hooks to allow reporting/error handling (bubenkoff)
+
+0.6.6
+-----
+
+- Fixes to unnecessary mentioning of pytest-bdd package files in py.test log with -v (bubenkoff)
+
+0.6.5
+-----
+
+- Compartibility with recent pytest (bubenkoff)
+
+0.6.4
+-----
+
+- More unicode fixes (amakhnach)
+
+0.6.3
+-----
+
+- Added unicode support for feature files. Removed buggy module replacement for scenario. (amakhnach)
+
+0.6.2
+-----
+
+- Removed unnecessary mention of pytest-bdd package files in py.test log with -v (bubenkoff)
+
+0.6.1
+-----
+
+- Step arguments in whens when there are no given arguments used. (amakhnach, bubenkoff)
+
+0.6.0
+-----
+
+- Added step arguments support. (curzona, olegpidsadnyi, bubenkoff)
+- Added checking of the step type order. (markon, olegpidsadnyi)
+
+0.5.2
+-----
+
+- Added extra info into output when FeatureError exception raises. (amakhnach)
+
+0.5.0
+-----
+
+- Added parametrization to scenarios
+- Coveralls.io integration
+- Test coverage improvement/fixes
+- Correct wrapping of step functions to preserve function docstring
+
+0.4.7
+-----
+
+- Fixed Python 3.3 support
+
+0.4.6
+-----
+
+- Fixed a bug when py.test --fixtures showed incorrect filenames for the steps.
+
+0.4.5
+-----
+
+- Fixed a bug with the reuse of the fixture by given steps being evaluated multiple times.
+
+0.4.3
+-----
+
+- Update the license file and PYPI related documentation.
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..811392e
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,7 @@
+Copyright (C) 2013-2014 Oleg Pidsadnyi, Anatoly Bubenkov and others
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..0c280e4
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,4 @@
+include *.rst
+include *.txt
+include setup.py
+include pytest_bdd/templates/*.mak
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..6d1dc19
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,23 @@
+# create virtual environment
+PATH := .env/bin:$(PATH)
+
+.env:
+ virtualenv .env
+
+# install all needed for development
+develop: .env
+ pip install -e . -r requirements-testing.txt tox python-coveralls
+
+coverage: develop
+ coverage run --source=pytest_bdd .env/bin/py.test tests
+ coverage report -m
+
+test: develop
+ tox
+
+coveralls: coverage
+ coveralls
+
+# clean the development envrironment
+clean:
+ -rm -rf .env
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..2354cdc
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,1242 @@
+BDD library for the py.test runner
+==================================
+
+.. image:: http://img.shields.io/pypi/v/pytest-bdd.svg
+ :target: https://pypi.python.org/pypi/pytest-bdd
+.. image:: http://img.shields.io/coveralls/pytest-dev/pytest-bdd/master.svg
+ :target: https://coveralls.io/r/pytest-dev/pytest-bdd
+.. image:: https://travis-ci.org/pytest-dev/pytest-bdd.svg?branch=master
+ :target: https://travis-ci.org/pytest-dev/pytest-bdd
+.. image:: https://readthedocs.org/projects/pytest-bdd/badge/?version=latest
+ :target: https://readthedocs.org/projects/pytest-bdd/?badge=latest
+ :alt: Documentation Status
+
+pytest-bdd implements a subset of Gherkin language for the automation of the project
+requirements testing and easier behavioral driven development.
+
+Unlike many other BDD tools it doesn't require a separate runner and benefits from
+the power and flexibility of the pytest. It allows to unify your unit and functional
+tests, easier continuous integration server configuration and maximal reuse of the
+tests setup.
+
+Pytest fixtures written for the unit tests can be reused for the setup and actions
+mentioned in the feature steps with dependency injection, which allows a true BDD
+just-enough specification of the requirements without maintaining any context object
+containing the side effects of the Gherkin imperative declarations.
+
+.. _behave: https://pypi.python.org/pypi/behave
+.. _pytest-splinter: https://github.com/pytest-dev/pytest-splinter
+
+Install pytest-bdd
+------------------
+
+::
+
+ pip install pytest-bdd
+
+
+Example
+-------
+
+An example test for a blog hosting software could look like this.
+Note that pytest-splinter_ is used to get the browser fixture.
+
+publish_article.feature:
+
+.. code-block:: gherkin
+
+ Feature: Blog
+ A site where you can publish your articles.
+
+ 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
+
+Note that only one feature is allowed per feature file.
+
+test_publish_article.py:
+
+.. code-block:: python
+
+ from pytest_bdd import scenario, given, when, then
+
+ @scenario('publish_article.feature', 'Publishing the article')
+ def test_publish():
+ pass
+
+
+ @given("I'm an author user")
+ def author_user(auth, author):
+ auth['user'] = author.user
+
+
+ @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('the article should be published')
+ def article_is_published(article):
+ article.refresh() # Refresh the object in the SQLAlchemy session
+ assert article.is_published
+
+
+Scenario decorator
+------------------
+
+Scenario decorator can accept such optional keyword arguments:
+
+* ``encoding`` - decode content of feature file in specific encoding. UTF-8 is default.
+* ``example_converters`` - mapping to pass functions to convert example values provided in feature files.
+
+Function decorated with `scenario` decorator behaves like a normal test function,
+which will be executed after all scenario steps.
+You can consider it as a normal pytest test function, e.g. order fixtures there,
+call other functions and make assertions:
+
+
+.. code-block:: python
+
+ from pytest_bdd import scenario, given, when, then
+
+ @scenario('publish_article.feature', 'Publishing the article')
+ def test_publish(browser):
+ assert article.title in browser.html
+
+
+Step aliases
+------------
+
+Sometimes it is needed to declare the same fixtures or steps with the
+different names for better readability. In order to use the same step
+function with multiple step names simply decorate it multiple times:
+
+.. code-block:: python
+
+ @given('I have an article')
+ @given('there\'s an article')
+ def article(author):
+ return create_test_article(author=author)
+
+Note that the given step aliases are independent and will be executed
+when mentioned.
+
+For example if you associate your resource to some owner or not. Admin
+user can’t be an author of the article, but articles should have a
+default author.
+
+.. code-block:: gherkin
+
+ Scenario: I'm the author
+ Given I'm an author
+ And I have an article
+
+
+ Scenario: I'm the admin
+ Given I'm the admin
+ And there is an article
+
+
+Given step scope
+----------------
+
+If you need your given step to be executed less than once per scenario (for example: once for module, session), you can
+pass optional ``scope`` argument:
+
+.. code-block:: python
+
+ @given('I have an article', scope='session')
+ def article(author):
+ return create_test_article(author=author)
+
+.. code-block:: gherkin
+
+ Scenario: I'm the author
+ Given I'm an author
+ And I have an article
+
+
+ Scenario: I'm the admin
+ Given I'm the admin
+ And there is an article
+
+
+For this example, step function for 'I have an article' given step will be executed once even though there are 2
+scenarios using it.
+Note that for other step types, it makes no sense to have scope larger than 'function' (the default) as they represent
+an action (when step), and assertion (then step).
+
+
+Step arguments
+--------------
+
+Often it's possible to reuse steps giving them a parameter(s).
+This allows to have single implementation and multiple use, so less code.
+Also opens the possibility to use same step twice in single scenario and with different arguments!
+And even more, there are several types of step parameter parsers at your disposal
+(idea taken from behave_ implementation):
+
+.. _pypi_parse: http://pypi.python.org/pypi/parse
+.. _pypi_parse_type: http://pypi.python.org/pypi/parse_type
+
+**string** (the default)
+ This is the default and can be considered as a `null` or `exact` parser. It parses no parameters
+ and matches the step name by equality of strings.
+**parse** (based on: pypi_parse_)
+ Provides a simple parser that replaces regular expressions for
+ step parameters with a readable syntax like ``{param:Type}``.
+ The syntax is inspired by the Python builtin ``string.format()``
+ function.
+ Step parameters must use the named fields syntax of pypi_parse_
+ in step definitions. The named fields are extracted,
+ optionally type converted and then used as step function arguments.
+ Supports type conversions by using type converters passed via `extra_types`
+**cfparse** (extends: pypi_parse_, based on: pypi_parse_type_)
+ Provides an extended parser with "Cardinality Field" (CF) support.
+ Automatically creates missing type converters for related cardinality
+ as long as a type converter for cardinality=1 is provided.
+ Supports parse expressions like:
+ * ``{values:Type+}`` (cardinality=1..N, many)
+ * ``{values:Type*}`` (cardinality=0..N, many0)
+ * ``{value:Type?}`` (cardinality=0..1, optional)
+ Supports type conversions (as above).
+**re**
+ This uses full regular expressions to parse the clause text. You will
+ need to use named groups "(?P<name>...)" to define the variables pulled
+ from the text and passed to your ``step()`` function.
+ Type conversion can only be done via `converters` step decorator argument (see example below).
+
+The default parser is `string`, so just plain one-to-one match to the keyword definition.
+Parsers except `string`, as well as their optional arguments are specified like:
+
+for `cfparse` parser
+
+.. code-block:: python
+
+ from pytest_bdd import parsers
+
+ @given(parsers.cfparse('there are {start:Number} cucumbers', extra_types=dict(Number=int)))
+ def start_cucumbers(start):
+ return dict(start=start, eat=0)
+
+for `re` parser
+
+.. code-block:: python
+
+ from pytest_bdd import parsers
+
+ @given(parsers.re(r'there are (?P<start>\d+) cucumbers'), converters=dict(start=int))
+ def start_cucumbers(start):
+ return dict(start=start, eat=0)
+
+
+Example:
+
+.. code-block:: gherkin
+
+ Scenario: Arguments for given, when, thens
+ Given there are 5 cucumbers
+
+ When I eat 3 cucumbers
+ And I eat 2 cucumbers
+
+ Then I should have 0 cucumbers
+
+
+The code will look like:
+
+.. code-block:: python
+
+ import re
+ from pytest_bdd import scenario, given, when, then, parsers
+
+
+ @scenario('arguments.feature', 'Arguments for given, when, thens')
+ def test_arguments():
+ pass
+
+
+ @given(parsers.parse('there are {start:d} cucumbers'))
+ def start_cucumbers(start):
+ return dict(start=start, eat=0)
+
+
+ @when(parsers.parse('I eat {eat:d} cucumbers'))
+ def eat_cucumbers(start_cucumbers, eat):
+ start_cucumbers['eat'] += eat
+
+
+ @then(parsers.parse('I should have {left:d} cucumbers'))
+ def should_have_left_cucumbers(start_cucumbers, start, left):
+ assert start_cucumbers['start'] == start
+ assert start - start_cucumbers['eat'] == left
+
+Example code also shows possibility to pass argument converters which may be useful if you need to postprocess step
+arguments after the parser.
+
+You can implement your own step parser. It's interface is quite simple. The code can looks like:
+
+.. code-block:: python
+
+ import re
+
+ from pytest_bdd import given, parsers
+
+ class MyParser(parsers.StepParser):
+
+ """Custom parser."""
+
+ def __init__(self, name, **kwargs):
+ """Compile regex."""
+ super(re, self).__init__(name)
+ self.regex = re.compile(re.sub('%(.+)%', '(?P<\1>.+)', self.name), **kwargs)
+
+ def parse_arguments(self, name):
+ """Get step arguments.
+
+ :return: `dict` of step arguments
+ """
+ return self.regex.match(name).groupdict()
+
+ def is_matching(self, name):
+ """Match given name with the step name."""
+ return bool(self.regex.match(name))
+
+ @given(parsers.parse('there are %start% cucumbers'))
+ def start_cucumbers(start):
+ return dict(start=start, eat=0)
+
+Step arguments are fixtures as well!
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Step arguments are injected into pytest `request` context as normal fixtures with the names equal to the names of the
+arguments. This opens a number of possibilies:
+
+* you can access step's argument as a fixture in other step function just by mentioning it as an argument (just like any othe pytest fixture)
+* if the name of the step argument clashes with existing fixture, it will be overridden by step's argument value; this way you can set/override the value for some fixture deeply inside of the fixture tree in a ad-hoc way by just choosing the proper name for the step argument.
+
+
+Override fixtures via given steps
+---------------------------------
+
+Dependency injection is not a panacea if you have complex structure of your test setup data. Sometimes there's a need
+such a given step which would imperatively change the fixture only for certain test (scenario), while for other tests
+it will stay untouched. To allow this, special parameter `target_fixture` exists in the `given` decorator:
+
+.. code-block:: python
+
+ from pytest_bdd import given
+
+ @pytest.fixture
+ def foo():
+ return "foo"
+
+
+ @given("I have injecting given", target_fixture="foo")
+ def injecting_given():
+ return "injected foo"
+
+
... 7837 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/pytest-bdd.git
More information about the Python-modules-commits
mailing list