-
Notifications
You must be signed in to change notification settings - Fork 225
/
Copy pathcucumber_helper.py
103 lines (83 loc) · 2.34 KB
/
cucumber_helper.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import textwrap
class OfType:
"""Helper object to help compare object type to initialization type"""
def __init__(self, type: type | None = None) -> None:
self.type = type
def __eq__(self, other: object) -> bool:
return isinstance(other, self.type) if self.type else True
def create_test(pytester):
pytester.makefile(
".ini",
pytest=textwrap.dedent(
"""
[pytest]
markers =
scenario-passing-tag
scenario-failing-tag
scenario-outline-passing-tag
feature-tag
"""
),
)
pytester.makefile(
".feature",
test=textwrap.dedent(
"""
@feature-tag
Feature: One passing scenario, one failing scenario
@scenario-passing-tag
Scenario: Passing
Given a passing step
And some other passing step
@scenario-failing-tag
Scenario: Failing
Given a passing step
And a failing step
@scenario-outline-passing-tag
Scenario Outline: Passing outline
Given type <type> and value <value>
Examples: example1
| type | value |
| str | hello |
| int | 42 |
| float | 1.0 |
Scenario: Skipping test
Given a skipping step
"""
),
)
pytester.makepyfile(
textwrap.dedent(
"""
import pytest
from pytest_bdd import given, when, scenario, parsers
@given('a passing step')
def _():
return 'pass'
@given('some other passing step')
def _():
return 'pass'
@given('a failing step')
def _():
raise Exception('Error')
@given('a skipping step')
def _():
pytest.skip('skipping')
@given(parsers.parse('type {type} and value {value}'))
def _():
return 'pass'
@scenario('test.feature', 'Passing')
def test_passing():
pass
@scenario('test.feature', 'Failing')
def test_failing():
pass
@scenario('test.feature', 'Passing outline')
def test_passing_outline():
pass
@scenario('test.feature', 'Skipping test')
def test_skipping():
pass
"""
)
)