(pytester)
| 4 | |
| 5 | |
| 6 | def test_steps_with_datatables(pytester): |
| 7 | pytester.makefile( |
| 8 | ".feature", |
| 9 | datatable=textwrap.dedent( |
| 10 | """\ |
| 11 | Feature: Manage user accounts |
| 12 | |
| 13 | Scenario: Creating a new user with roles and permissions |
| 14 | Given the following user details: |
| 15 | | name | email | age | |
| 16 | | John | john@example.com | 30 | |
| 17 | | Alice | alice@example.com | 25 | |
| 18 | |
| 19 | When the user is assigned the following roles: |
| 20 | | role | description | |
| 21 | | Admin | Full access to the system | |
| 22 | | Contributor | Can add content | |
| 23 | |
| 24 | And this step has no datatable |
| 25 | |
| 26 | Then the user should have the following permissions: |
| 27 | | permission | allowed | |
| 28 | | view dashboard | true | |
| 29 | | edit content | true | |
| 30 | | delete content | false | |
| 31 | """ |
| 32 | ), |
| 33 | ) |
| 34 | pytester.makeconftest( |
| 35 | textwrap.dedent( |
| 36 | """\ |
| 37 | from pytest_bdd import given, when, then |
| 38 | from pytest_bdd.utils import dump_obj |
| 39 | |
| 40 | |
| 41 | @given("the following user details:") |
| 42 | def _(datatable): |
| 43 | given_datatable = datatable |
| 44 | dump_obj(given_datatable) |
| 45 | |
| 46 | |
| 47 | @when("the user is assigned the following roles:") |
| 48 | def _(datatable): |
| 49 | when_datatable = datatable |
| 50 | dump_obj(when_datatable) |
| 51 | |
| 52 | |
| 53 | @when("this step has no datatable") |
| 54 | def _(): |
| 55 | pass |
| 56 | |
| 57 | |
| 58 | @then("the user should have the following permissions:") |
| 59 | def _(datatable): |
| 60 | then_datatable = datatable |
| 61 | dump_obj(then_datatable) |
| 62 | |
| 63 | """ |
nothing calls this directly
no test coverage detected
searching dependent graphs…