Skip to content

Commit

Permalink
docs: Python README install and API code snippets
Browse files Browse the repository at this point in the history
- Test the README code snippets through pytest
  • Loading branch information
kieran-ryan committed Jan 12, 2025
1 parent a45ee15 commit 8b1c8ff
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
40 changes: 39 additions & 1 deletion python/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,46 @@ SEE ALSO:

* https://cucumber.io/docs/cucumber/api/#tag-expressions

Getting Started
-----------------------------------------------------------------

EXAMPLE:
Cucumber Tag Expressions is available as `cucumber-tag-expressions <https://pypi.org/project/cucumber-tag-expressions/>`_ on PyPI.

.. code-block:: console
pip install cucumber-tag-expressions
Parse tag expressions and evaluate them against a set of tags.

.. code-block:: python
>>> from cucumber_tag_expressions import parse
>>> # Tagged with @fast
>>> fast = parse("@fast")
>>> fast({"@fast", "@wip"})
True
>>> fast({"@performance", "@slow"})
False
>>> # Tagged with @wip and not @slow
>>> wip_not_slow = parse("@wip and not @slow")
>>> wip_not_slow({"@wip", "@home"})
True
>>> wip_not_slow({"wet", "warm", "raining"})
False
>>> # Tagged with both `@fast` and `@integration`
>>> fast_integration = parse("@integration and @fast")
>>> fast_integration({"@integration", "@fast", "@other"})
True
>>> fast_integration({"@system", "@fast"})
False
>>> # Tagged with either @login or @registration
>>> auth_pages = parse("@login or @registration")
>>> auth_pages({"@account", "@login"})
True
>>> auth_pages({"@admin", "@account"})
False
Test Runner Usage
-----------------------------------------------------------------

A cucumber test runner selects some scenarios by using tag-expressions and runs them:
Expand Down
4 changes: 2 additions & 2 deletions python/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

[pytest]
minversion = 3.2
testpaths = tests
testpaths = tests README.rst
python_files = test_*.py
addopts =
--metadata PACKAGE_UNDER_TEST tag-expressions
--html=build/testing/report.html --self-contained-html
--junit-xml=build/testing/report.xml
--doctest-modules

# -- BACKWARD COMPATIBILITY: pytest < 2.8
# norecursedirs = .git .tox attic build dist py.requirements tmp* _WORKSPACE

0 comments on commit 8b1c8ff

Please sign in to comment.