Skip to content

Commit a589676

Browse files
authored
Merge branch 'master' into add-rule
2 parents dd145a2 + a01ca25 commit a589676

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tests/scripts/test_main.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import sys
5+
import textwrap
56

67
from pytest_bdd.scripts import main
78

@@ -16,3 +17,67 @@ def test_main(monkeypatch, capsys):
1617
out, err = capsys.readouterr()
1718
assert "usage: pytest-bdd [-h]" in err
1819
assert "pytest-bdd: error:" in err
20+
21+
22+
def test_step_definitions_found_using_main(pytester):
23+
"""Issue 173: Ensure step definitions are found when using pytest.main."""
24+
pytester.makefile(
25+
".feature",
26+
outline=textwrap.dedent(
27+
"""\
28+
Feature: Outlined Scenarios
29+
30+
Scenario Outline: Outlined given, when, then
31+
Given there are <start> cucumbers
32+
When I eat <eat> cucumbers
33+
Then I should have <left> cucumbers
34+
35+
Examples:
36+
| start | eat | left |
37+
| 12 | 5 | 7 |
38+
"""
39+
),
40+
)
41+
42+
pytester.makepyfile(
43+
textwrap.dedent(
44+
"""\
45+
from pytest_bdd import given, when, then, parsers, scenarios
46+
47+
scenarios(".")
48+
49+
@given(parsers.parse("there are {start:d} cucumbers"), target_fixture="cucumbers")
50+
def _(start):
51+
assert isinstance(start, int)
52+
return {"start": start}
53+
54+
55+
@when(parsers.parse("I eat {eat:g} cucumbers"))
56+
def _(cucumbers, eat):
57+
assert isinstance(eat, float)
58+
cucumbers["eat"] = eat
59+
60+
61+
@then(parsers.parse("I should have {left} cucumbers"))
62+
def _(cucumbers, left):
63+
assert isinstance(left, str)
64+
assert cucumbers["start"] - cucumbers["eat"] == int(left)
65+
"""
66+
)
67+
)
68+
69+
pytester.makepyfile(
70+
main=textwrap.dedent(
71+
"""\
72+
import pytest
73+
import os
74+
75+
# Programmatically run pytest
76+
if __name__ == "__main__":
77+
pytest.main([os.path.abspath("test_step_definitions_found_using_main.py")])
78+
"""
79+
)
80+
)
81+
82+
result = pytester.runpython(pytester.path / "main.py")
83+
result.assert_outcomes(passed=1, failed=0)

0 commit comments

Comments
 (0)