Skip to content

Commit 7c6ba36

Browse files
Fixes #201 and pytest compatibility. (#232)
* Fixes #201 and pytest compatibility. * Review comments
1 parent 8c54f35 commit 7c6ba36

File tree

11 files changed

+50
-11
lines changed

11 files changed

+50
-11
lines changed

CHANGES.rst

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

4+
5+
2.20.0
6+
------
7+
8+
- Added support for But steps (olegpidsadnyi)
9+
- Fixed compatibility with pytest 3.3.2 (olegpidsadnyi)
10+
- MInimal required version of pytest is now 2.8.1 since it doesn't support earlier versions (olegpidsadnyi)
11+
12+
413
2.19.0
514
------
615

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ Install pytest-bdd
3535
pip install pytest-bdd
3636

3737

38+
The minimal required version of pytest is 2.8.1.
39+
40+
3841
Example
3942
-------
4043

pytest_bdd/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
from pytest_bdd.steps import given, when, then
44
from pytest_bdd.scenario import scenario, scenarios
55

6-
__version__ = '2.19.0'
6+
__version__ = '2.20.0'
77

88
__all__ = [given.__name__, when.__name__, then.__name__, scenario.__name__, scenarios.__name__]

pytest_bdd/feature.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
("When ", types.WHEN),
5353
("Then ", types.THEN),
5454
("@", types.TAG),
55-
("And ", None), # Unknown step type,
55+
# Continuation of the previously mentioned step type
56+
("And ", None),
57+
("But ", None),
5658
]
5759

5860
STEP_PARAM_RE = re.compile("\<(.+?)\>")
@@ -297,7 +299,7 @@ def __init__(self, basedir, filename, encoding="utf-8", strict_gherkin=True):
297299
if not strict_gherkin:
298300
allowed_prev_mode += (types.WHEN, )
299301

300-
if not scenario and prev_mode not in allowed_prev_mode and mode in types.STEP_TYPES:
302+
if not scenario and prev_mode not in allowed_prev_mode and mode in types.STEP_TYPES:
301303
raise exceptions.FeatureError(
302304
"Step definition outside of a Scenario or a Background", line_number, clean_line, filename)
303305

pytest_bdd/steps.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,19 @@ def inject_fixture(request, arg, value):
304304
fd.cached_result = (value, 0, None)
305305

306306
old_fd = get_request_fixture_defs(request).get(arg)
307-
old_value = get_fixture_value_raw(request, arg)
308307
add_fixturename = arg not in request.fixturenames
309308

309+
old_value = get_fixture_value_raw(request, arg) # Compatibility with pytest < 3.3.2
310+
310311
def fin():
311312
request._fixturemanager._arg2fixturedefs[arg].remove(fd)
312313
get_request_fixture_defs(request)[arg] = old_fd
313-
set_fixture_value(request, arg, old_value)
314+
314315
if add_fixturename:
315316
get_request_fixture_names(request).remove(arg)
316317

318+
set_fixture_value(request, arg, old_value) # Compatibility with pytest < 3.3.2
319+
317320
request.addfinalizer(fin)
318321

319322
# inject fixture definition

pytest_bdd/utils.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,31 @@ def get_fixture_value(request, name):
3737

3838

3939
def get_fixture_value_raw(request, name):
40-
"""Set the given raw fixture value from the pytest request object."""
40+
"""Set the given raw fixture value from the pytest request object.
41+
42+
:note: Compatibility with pytest < 3.3.2
43+
"""
4144
try:
4245
return request._fixture_values.get(name)
4346
except AttributeError:
44-
return request._funcargs.get(name)
47+
try:
48+
return request._funcargs.get(name)
49+
except AttributeError:
50+
pass
4551

4652

4753
def set_fixture_value(request, name, value):
48-
"""Set the given fixture value on the pytest request object."""
54+
"""Set the given fixture value on the pytest request object.
55+
56+
:note: Compatibility with pytest < 3.3.2
57+
"""
4958
try:
5059
request._fixture_values[name] = value
5160
except AttributeError:
52-
request._funcargs[name] = value
61+
try:
62+
request._funcargs[name] = value
63+
except AttributeError:
64+
pass
5365

5466

5567
def get_request_fixture_defs(request):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def run_tests(self):
7575
"Mako",
7676
"parse",
7777
"parse_type",
78-
"pytest>=2.6.0",
78+
"pytest>=2.8.1",
7979
"six>=1.9.0",
8080
],
8181
# the following makes a plugin available to py.test

tests/feature/steps.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Scenario: Executed step by step
1010
And I append 2 to the list
1111
And I append 3 to the list
1212
Then foo should have value "foo"
13-
And the list should be [1, 2, 3]
13+
But the list should be [1, 2, 3]
1414

1515

1616
Scenario: When step can be the first

tests/feature/test_scenarios.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
def test_scenarios(testdir):
66
"""Test scenarios shortcut."""
7+
testdir.makeini("""
8+
[pytest]
9+
console_output_style=classic
10+
""")
711
testdir.makeconftest("""
812
import pytest
913
from pytest_bdd import given

tests/feature/test_steps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ def test_when_step_validation_error():
195195

196196
def test_step_trace(testdir):
197197
"""Test step trace."""
198+
testdir.makeini("""
199+
[pytest]
200+
console_output_style=classic
201+
""")
202+
198203
testdir.makefile('.feature', test="""
199204
Scenario: When step has failure
200205
Given I have a bar

0 commit comments

Comments
 (0)