Skip to content

Commit 76ed2ec

Browse files
Cleanuptests2 (#370)
* Cleaning up tests * Changelog entry
1 parent 6ba231f commit 76ed2ec

18 files changed

+824
-400
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
=========
33

4+
5+
- Fixes pytest-xdist 2.0 compatibility (olegpidsadnyi) #369.
6+
7+
48
3.4.0
59
-----
610

pytest_bdd/cucumber_json.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def add_options(parser):
3535

3636
def configure(config):
3737
cucumber_json_path = config.option.cucumber_json_path
38-
# prevent opening json log on slave nodes (xdist)
39-
if cucumber_json_path and not hasattr(config, "slaveinput"):
38+
# prevent opening json log on worker nodes (xdist)
39+
if cucumber_json_path and not hasattr(config, "workerinput"):
4040
config._bddcucumberjson = LogBDDCucumberJSON(cucumber_json_path, expand=config.option.expand)
4141
config.pluginmanager.register(config._bddcucumberjson)
4242

tests/args/args_steps.feature

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/args/cfparse/test_args.py

Lines changed: 165 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,180 @@
11
"""Step arguments tests."""
22

3-
import functools
4-
from pytest_bdd import given, parsers, scenario, then, when
3+
import textwrap
54

6-
import pytest
75

8-
from pytest_bdd import exceptions
6+
def test_every_steps_takes_param_with_the_same_name(testdir):
7+
testdir.makefile(
8+
".feature",
9+
arguments=textwrap.dedent(
10+
"""\
11+
Feature: Step arguments
12+
Scenario: Every step takes a parameter with the same name
13+
Given I have 1 Euro
14+
When I pay 2 Euro
15+
And I pay 1 Euro
16+
Then I should have 0 Euro
17+
And I should have 999999 Euro # In my dream...
18+
19+
"""
20+
),
21+
)
22+
23+
testdir.makepyfile(
24+
textwrap.dedent(
25+
"""\
26+
import pytest
27+
from pytest_bdd import parsers, given, when, then, scenario
28+
29+
@scenario("arguments.feature", "Every step takes a parameter with the same name")
30+
def test_arguments():
31+
pass
32+
33+
@pytest.fixture
34+
def values():
35+
return [1, 2, 1, 0, 999999]
36+
37+
38+
@given(parsers.cfparse("I have {euro:d} Euro"))
39+
def i_have(euro, values):
40+
assert euro == values.pop(0)
41+
42+
43+
@when(parsers.cfparse("I pay {euro:d} Euro"))
44+
def i_pay(euro, values, request):
45+
assert euro == values.pop(0)
46+
47+
48+
@then(parsers.cfparse("I should have {euro:d} Euro"))
49+
def i_should_have(euro, values):
50+
assert euro == values.pop(0)
51+
52+
"""
53+
)
54+
)
55+
result = testdir.runpytest()
56+
result.assert_outcomes(passed=1)
57+
58+
59+
def test_argument_in_when_step_1(testdir):
60+
testdir.makefile(
61+
".feature",
62+
arguments=textwrap.dedent(
63+
"""\
64+
Feature: Step arguments
65+
Scenario: Argument in when, step 1
66+
Given I have an argument 1
67+
When I get argument 5
68+
Then My argument should be 5
69+
"""
70+
),
71+
)
72+
73+
testdir.makepyfile(
74+
textwrap.dedent(
75+
"""\
76+
from pytest_bdd import parsers, given, when, then, scenario
77+
78+
@scenario("arguments.feature", "Argument in when, step 1")
79+
def test_arguments():
80+
pass
81+
82+
@given(parsers.cfparse("I have an argument {arg:Number}", extra_types=dict(Number=int)))
83+
def argument(arg):
84+
return dict(arg=arg)
85+
86+
87+
@when(parsers.cfparse("I get argument {arg:d}"))
88+
def get_argument(argument, arg):
89+
argument["arg"] = arg
90+
91+
92+
@then(parsers.cfparse("My argument should be {arg:d}"))
93+
def assert_that_my_argument_is_arg(argument, arg):
94+
assert argument["arg"] == arg
95+
96+
"""
97+
)
98+
)
99+
result = testdir.runpytest()
100+
result.assert_outcomes(passed=1)
101+
102+
103+
def test_argument_in_when_step_2(testdir):
104+
testdir.makefile(
105+
".feature",
106+
arguments=textwrap.dedent(
107+
"""\
108+
Feature: Step arguments
109+
Scenario: Argument in when, step 2
110+
Given I have an argument 1
111+
When I get argument 10
112+
Then My argument should be 10
113+
"""
114+
),
115+
)
9116

10-
scenario_when = functools.partial(scenario, "../when_arguments.feature")
117+
testdir.makepyfile(
118+
textwrap.dedent(
119+
"""\
120+
from pytest_bdd import parsers, given, when, then, scenario
11121
12-
scenario_args = functools.partial(scenario, "../args_steps.feature")
122+
@scenario("arguments.feature", "Argument in when, step 2")
123+
def test_arguments():
124+
pass
13125
126+
@given(parsers.cfparse("I have an argument {arg:Number}", extra_types=dict(Number=int)))
127+
def argument(arg):
128+
return dict(arg=arg)
14129
15-
@scenario_args("Every step takes a parameter with the same name")
16-
def test_steps():
17-
pass
18130
131+
@when(parsers.cfparse("I get argument {arg:d}"))
132+
def get_argument(argument, arg):
133+
argument["arg"] = arg
19134
20-
@scenario_when("Argument in when, step 1")
21-
def test_argument_in_when_step_1():
22-
pass
23135
136+
@then(parsers.cfparse("My argument should be {arg:d}"))
137+
def assert_that_my_argument_is_arg(argument, arg):
138+
assert argument["arg"] == arg
24139
25-
@scenario_when("Argument in when, step 2")
26-
def test_argument_in_when_step_2():
27-
pass
140+
"""
141+
)
142+
)
143+
result = testdir.runpytest()
144+
result.assert_outcomes(passed=1)
28145

29146

30-
def test_multiple_given(request):
147+
def test_multiple_given(testdir):
31148
"""Using the same given fixture raises an error."""
32-
33-
@scenario_args("Using the same given fixture raises an error")
34-
def test():
35-
pass
36-
37-
with pytest.raises(exceptions.GivenAlreadyUsed):
38-
test(request)
39-
40-
41-
@given(parsers.cfparse("I have {euro:d} Euro"))
42-
def i_have(euro, values):
43-
assert euro == values.pop(0)
44-
45-
46-
@when(parsers.cfparse("I pay {euro:d} Euro"))
47-
def i_pay(euro, values, request):
48-
assert euro == values.pop(0)
49-
50-
51-
@then(parsers.cfparse("I should have {euro:d} Euro"))
52-
def i_should_have(euro, values):
53-
assert euro == values.pop(0)
54-
55-
56-
@given(parsers.cfparse("I have an argument {arg:Number}", extra_types=dict(Number=int)))
57-
def argument(arg):
58-
"""I have an argument."""
59-
return dict(arg=arg)
60-
61-
62-
@when(parsers.cfparse("I get argument {arg:d}"))
63-
def get_argument(argument, arg):
64-
"""Getting argument."""
65-
argument["arg"] = arg
66-
67-
68-
@then(parsers.cfparse("My argument should be {arg:d}"))
69-
def assert_that_my_argument_is_arg(argument, arg):
70-
"""Assert that arg from when equals arg."""
71-
assert argument["arg"] == arg
149+
testdir.makefile(
150+
".feature",
151+
arguments=textwrap.dedent(
152+
"""\
153+
Feature: Step arguments
154+
Scenario: Using the same given fixture raises an error
155+
Given I have 1 Euro
156+
And I have 2 Euro
157+
"""
158+
),
159+
)
160+
testdir.makepyfile(
161+
textwrap.dedent(
162+
"""\
163+
from pytest_bdd import parsers, given, scenario
164+
165+
@scenario("arguments.feature", "Using the same given fixture raises an error")
166+
def test_arguments():
167+
pass
168+
169+
@given(parsers.cfparse("I have {euro:d} Euro"))
170+
def i_have(euro):
171+
return euro
172+
173+
"""
174+
)
175+
)
176+
result = testdir.runpytest()
177+
result.assert_outcomes(failed=1)
178+
result.stdout.fnmatch_lines(
179+
'*GivenAlreadyUsed: Fixture "i_have" that implements this "I have 2 Euro" given step has been already used.*'
180+
)

tests/args/conftest.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)