Skip to content

Commit 61bf486

Browse files
authored
Merge branch 'master' into generated-steps-raise-notimplemented
2 parents eded49a + 2b60fbc commit 61bf486

File tree

12 files changed

+27
-107
lines changed

12 files changed

+27
-107
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ matrix:
66
include:
77
- python: "2.7"
88
env: TOXENV=py27-pytestlatest-linters
9-
- env: TOXENV=py27-pytest30
10-
- env: TOXENV=py27-pytest31
11-
- env: TOXENV=py27-pytest32
129
- env: TOXENV=py27-pytest33
1310
- env: TOXENV=py27-pytest34
1411
- env: TOXENV=py27-pytest35

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
Unreleased
55
----------
66

7+
- Drop support for pytest < 3.3.2
78
- Step definitions generated by `pytest-bdd generate` will now `raise NotImplementedError` by default.
89

910
3.0.2

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,24 +168,24 @@ pass optional ``scope`` argument:
168168

169169
.. code-block:: python
170170
171-
@given('I have an article', scope='session')
171+
@given('there is an article', scope='session')
172172
def article(author):
173173
return create_test_article(author=author)
174174
175175
.. code-block:: gherkin
176176
177177
Scenario: I'm the author
178178
Given I'm an author
179-
And I have an article
179+
And there is an article
180180
181181
182182
Scenario: I'm the admin
183183
Given I'm the admin
184184
And there is an article
185185
186186
187-
For this example, step function for 'I have an article' given step will be executed once even though there are 2
188-
scenarios using it.
187+
In this example, the step function for the 'there is an article' given step will be executed once, even though there
188+
are 2 scenarios using it.
189189
Note that for other step types, it makes no sense to have scope larger than 'function' (the default) as they represent
190190
an action (when step), and assertion (then step).
191191

pytest_bdd/scenario.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
recreate_function,
3939
)
4040
from .types import GIVEN
41-
from .utils import CONFIG_STACK, get_args, get_fixture_value
41+
from .utils import CONFIG_STACK, get_args
4242

4343
if six.PY3: # pragma: no cover
4444
import runpy
@@ -70,7 +70,7 @@ def find_argumented_step_fixture_name(name, type_, fixturemanager, request=None)
7070
parser_name = get_step_fixture_name(parser.name, type_)
7171
if request:
7272
try:
73-
get_fixture_value(request, parser_name)
73+
request.getfixturevalue(parser_name)
7474
except pytest_fixtures.FixtureLookupError:
7575
continue
7676
return parser_name
@@ -88,12 +88,12 @@ def _find_step_function(request, step, scenario, encoding):
8888
"""
8989
name = step.name
9090
try:
91-
return get_fixture_value(request, get_step_fixture_name(name, step.type, encoding))
91+
return request.getfixturevalue(get_step_fixture_name(name, step.type, encoding))
9292
except pytest_fixtures.FixtureLookupError:
9393
try:
9494
name = find_argumented_step_fixture_name(name, step.type, request._fixturemanager, request)
9595
if name:
96-
return get_fixture_value(request, name)
96+
return request.getfixturevalue(name)
9797
raise
9898
except pytest_fixtures.FixtureLookupError:
9999
raise exceptions.StepDefinitionNotFoundError(
@@ -128,7 +128,7 @@ def _execute_step_function(request, scenario, step, step_func):
128128
kw["step_func_args"] = {}
129129
try:
130130
# Get the step argument values.
131-
kwargs = dict((arg, get_fixture_value(request, arg)) for arg in get_args(step_func))
131+
kwargs = dict((arg, request.getfixturevalue(arg)) for arg in get_args(step_func))
132132
kw["step_func_args"] = kwargs
133133

134134
request.config.hook.pytest_bdd_before_step_call(**kw)

pytest_bdd/steps.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ def article(author):
4949
StepError,
5050
)
5151
from .parsers import get_parser
52-
from .utils import get_args, get_fixture_value, get_fixture_value_raw, set_fixture_value, get_request_fixture_defs, \
53-
get_request_fixture_names
52+
from .utils import get_args
5453

5554

5655
def get_step_fixture_name(name, type_, encoding=None):
@@ -82,7 +81,7 @@ def given(name, fixture=None, converters=None, scope='function', target_fixture=
8281
module = get_caller_module()
8382

8483
def step_func(request):
85-
return get_fixture_value(request, fixture)
84+
return request.getfixturevalue(fixture)
8685

8786
step_func.step_type = GIVEN
8887
step_func.converters = converters
@@ -162,7 +161,7 @@ def decorator(func):
162161
func = pytest.fixture(scope=scope)(func)
163162

164163
def step_func(request):
165-
result = get_fixture_value(request, func.__name__)
164+
result = request.getfixturevalue(func.__name__)
166165
if target_fixture:
167166
inject_fixture(request, target_fixture, result)
168167
return result
@@ -305,26 +304,21 @@ def inject_fixture(request, arg, value):
305304
fd = pytest_fixtures.FixtureDef(**fd_kwargs)
306305
fd.cached_result = (value, 0, None)
307306

308-
old_fd = get_request_fixture_defs(request).get(arg)
307+
old_fd = request._fixture_defs.get(arg)
309308
add_fixturename = arg not in request.fixturenames
310309

311-
old_value = get_fixture_value_raw(request, arg) # Compatibility with pytest < 3.3.2
312-
313310
def fin():
314311
request._fixturemanager._arg2fixturedefs[arg].remove(fd)
315-
get_request_fixture_defs(request)[arg] = old_fd
312+
request._fixture_defs[arg] = old_fd
316313

317314
if add_fixturename:
318-
get_request_fixture_names(request).remove(arg)
319-
320-
set_fixture_value(request, arg, old_value) # Compatibility with pytest < 3.3.2
315+
request._pyfuncitem._fixtureinfo.names_closure.remove(arg)
321316

322317
request.addfinalizer(fin)
323318

324319
# inject fixture definition
325320
request._fixturemanager._arg2fixturedefs.setdefault(arg, []).insert(0, fd)
326321
# inject fixture value in request cache
327-
get_request_fixture_defs(request)[arg] = fd
328-
set_fixture_value(request, arg, value)
322+
request._fixture_defs[arg] = fd
329323
if add_fixturename:
330-
get_request_fixture_names(request).append(arg)
324+
request._pyfuncitem._fixtureinfo.names_closure.append(arg)

pytest_bdd/utils.py

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -25,69 +25,6 @@ def get_args(func):
2525
return inspect.getargspec(func).args
2626

2727

28-
def get_fixture_value(request, name):
29-
"""Get the given fixture from the pytest request object.
30-
31-
getfuncargvalue() is deprecated in pytest 3.0, so we need to use
32-
getfixturevalue() there.
33-
"""
34-
try:
35-
getfixturevalue = request.getfixturevalue
36-
except AttributeError:
37-
getfixturevalue = request.getfuncargvalue
38-
return getfixturevalue(name)
39-
40-
41-
def get_fixture_value_raw(request, name):
42-
"""Set the given raw fixture value from the pytest request object.
43-
44-
:note: Compatibility with pytest < 3.3.2
45-
"""
46-
try:
47-
return request._fixture_values.get(name)
48-
except AttributeError:
49-
try:
50-
return request._funcargs.get(name)
51-
except AttributeError:
52-
pass
53-
54-
55-
def set_fixture_value(request, name, value):
56-
"""Set the given fixture value on the pytest request object.
57-
58-
:note: Compatibility with pytest < 3.3.2
59-
"""
60-
try:
61-
request._fixture_values[name] = value
62-
except AttributeError:
63-
try:
64-
request._funcargs[name] = value
65-
except AttributeError:
66-
pass
67-
68-
69-
def get_request_fixture_defs(request):
70-
"""Get the internal list of FixtureDefs cached into the given request object.
71-
72-
Compatibility with pytest 3.0.
73-
"""
74-
try:
75-
return request._fixture_defs
76-
except AttributeError:
77-
return getattr(request, "_fixturedefs", {})
78-
79-
80-
def get_request_fixture_names(request):
81-
"""Get list of fixture names for the given FixtureRequest.
82-
83-
Get the internal and mutable list of fixture names in the enclosing scope of
84-
the given request object.
85-
86-
Compatibility with pytest 3.0.
87-
"""
88-
return request._pyfuncitem._fixtureinfo.names_closure
89-
90-
9128
def get_parametrize_markers_args(node):
9229
"""In pytest 3.6 new API to access markers has been introduced and it deprecated
9330
MarkInfo objects.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def run_tests(self):
7676
"parse",
7777
"parse_type",
7878
"py",
79-
"pytest>=2.9.0",
79+
"pytest>=3.0.0",
8080
"six>=1.9.0",
8181
],
8282
# the following makes a plugin available to py.test

tests/feature/test_multiline.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
scenario,
1111
then,
1212
)
13-
from pytest_bdd.utils import get_fixture_value
1413

1514

1615
@pytest.mark.parametrize(["feature_text", "expected_text"], [
@@ -73,7 +72,7 @@ def test_multiline(request, tmpdir, feature_text, expected_text):
7372

7473
@scenario(file_name.strpath, 'Multiline step using sub indentation')
7574
def test_multiline(request):
76-
assert get_fixture_value(request, 'i_have_text') == expected_text
75+
assert request.getfixturevalue('i_have_text') == expected_text
7776
test_multiline(request)
7877

7978

tests/library/child/test_local_override.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from pytest_bdd import given
77
from pytest_bdd.steps import get_step_fixture_name, GIVEN
8-
from pytest_bdd.utils import get_fixture_value
98

109

1110
@given('I have locally overriden fixture')
@@ -22,11 +21,11 @@ def test_override(request, overridable):
2221
"""Test locally overriden fixture."""
2322

2423
# Test the fixture is also collected by the text name
25-
fixture = get_fixture_value(request, get_step_fixture_name('I have locally overriden fixture', GIVEN))
24+
fixture = request.getfixturevalue(get_step_fixture_name('I have locally overriden fixture', GIVEN))
2625
assert fixture(request) == 'local'
2726

2827
# 'I have the overriden fixture' stands for overridable and is overriden locally
29-
fixture = get_fixture_value(request, get_step_fixture_name('I have the overriden fixture', GIVEN))
28+
fixture = request.getfixturevalue(get_step_fixture_name('I have the overriden fixture', GIVEN))
3029
assert fixture(request) == 'local'
3130

3231
assert overridable == 'local'

tests/library/test_parent.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
Check the parent givens are collected and overriden in the local conftest.
44
"""
55
from pytest_bdd.steps import get_step_fixture_name, WHEN
6-
from pytest_bdd.utils import get_fixture_value
76

87

98
def test_parent(parent, overridable):
@@ -17,4 +16,4 @@ def test_parent(parent, overridable):
1716

1817
def test_global_when_step(request):
1918
"""Test when step defined in the parent conftest."""
20-
get_fixture_value(request, get_step_fixture_name('I use a when step from the parent conftest', WHEN))
19+
request.getfixturevalue(get_step_fixture_name('I use a when step from the parent conftest', WHEN))

0 commit comments

Comments
 (0)