File: test_alias.py

package info (click to toggle)
pytest-bdd 7.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 540 kB
  • sloc: python: 3,535; makefile: 134
file content (60 lines) | stat: -rw-r--r-- 1,585 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Test step alias when decorated multiple times."""

import textwrap


def test_step_alias(pytester):
    pytester.makefile(
        ".feature",
        alias=textwrap.dedent(
            """\
            Feature: Step aliases
                Scenario: Multiple step aliases
                    Given I have an empty list
                    And I have foo (which is 1) in my list
                    # Alias of the "I have foo (which is 1) in my list"
                    And I have bar (alias of foo) in my list

                    When I do crash (which is 2)
                    And I do boom (alias of crash)
                    Then my list should be [1, 1, 2, 2]
            """
        ),
    )

    pytester.makepyfile(
        textwrap.dedent(
            """\
        import pytest
        from pytest_bdd import given, when, then, scenario

        @scenario("alias.feature", "Multiple step aliases")
        def test_alias():
            pass


        @given("I have an empty list", target_fixture="results")
        def _():
            return []


        @given("I have foo (which is 1) in my list")
        @given("I have bar (alias of foo) in my list")
        def _(results):
            results.append(1)


        @when("I do crash (which is 2)")
        @when("I do boom (alias of crash)")
        def _(results):
            results.append(2)


        @then("my list should be [1, 1, 2, 2]")
        def _(results):
            assert results == [1, 1, 2, 2]
        """
        )
    )
    result = pytester.runpytest()
    result.assert_outcomes(passed=1)