Skip to content

Commit d088c69

Browse files
authored
Merge branch 'master' into unused-params-validation
2 parents 2f5fdd5 + d4f74d2 commit d088c69

File tree

10 files changed

+75
-28
lines changed

10 files changed

+75
-28
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: ["3.6", "3.7", "3.8", "3.9", 3.10.0-rc.2]
14+
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
1515

1616
steps:
1717
- uses: actions/checkout@v2

.pre-commit-config.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
44
- repo: https://github.com/psf/black
5-
rev: 21.12b0
5+
# If you update the version here, also update it in tox.ini (py*-pytestlatest-linters)
6+
rev: 22.1.0
67
hooks:
78
- id: black
89
- repo: https://github.com/pycqa/isort
@@ -18,7 +19,7 @@ repos:
1819
- id: check-yaml
1920
- id: check-added-large-files
2021
- repo: https://github.com/asottile/pyupgrade
21-
rev: v2.29.1
22+
rev: v2.31.0
2223
hooks:
2324
- id: pyupgrade
24-
args: [--py36-plus]
25+
args: [--py37-plus]

CHANGES.rst

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ This release introduces breaking changes in order to be more in line with the of
1010
- Removed feature level examples for the gherkin compatibility (olegpidsadnyi)
1111
- Removed vertical examples for the gherkin compatibility (olegpidsadnyi)
1212
- Step arguments are no longer fixtures (olegpidsadnyi)
13+
- Drop support of python 3.6, pytest 4 (elchupanebrej)
14+
- Step definitions can have "yield" statements again (4.0 release broke it). They will be executed as normal fixtures: code after the yield is executed during teardown of the test. (youtux)
1315
- Scenario outlines unused example parameter validation is removed (olegpidsadnyi)
1416

1517

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[build-system]
2-
requires = ["setuptools>=42", "wheel"]
2+
requires = ["setuptools>=58", "wheel"]
33
build-backend = "setuptools.build_meta"
44

55
[tool.black]
66
line-length = 120
7-
target-version = ['py36', 'py37', 'py38']
7+
target-version = ["py37", "py38", "py39", "py310"]
88

99
[tool.isort]
1010
profile = "black"

pytest_bdd/cucumber_json.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _get_result(self, step, report, error_message=False):
6161
result = {"status": "failed", "error_message": str(report.longrepr) if error_message else ""}
6262
elif report.skipped:
6363
result = {"status": "skipped"}
64-
result["duration"] = int(math.floor((10 ** 9) * step["duration"])) # nanosec
64+
result["duration"] = int(math.floor((10**9) * step["duration"])) # nanosec
6565
return result
6666

6767
def _serialize_tags(self, item):

pytest_bdd/scenario.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import typing
1717

1818
import pytest
19-
from _pytest.fixtures import FixtureLookupError
19+
from _pytest.fixtures import FixtureLookupError, call_fixture_func
2020

2121
from . import exceptions
2222
from .feature import get_feature, get_features
@@ -112,8 +112,9 @@ def _execute_step_function(request, scenario, step, step_func):
112112

113113
request.config.hook.pytest_bdd_before_step_call(**kw)
114114
target_fixture = getattr(step_func, "target_fixture", None)
115-
# Execute the step.
116-
return_value = step_func(**kwargs)
115+
116+
# Execute the step as if it was a pytest fixture, so that we can allow "yield" statements in it
117+
return_value = call_fixture_func(fixturefunc=step_func, request=request, kwargs=kwargs)
117118
if target_fixture:
118119
inject_fixture(request, target_fixture, return_value)
119120

setup.cfg

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ classifiers =
1919
Topic :: Software Development :: Libraries
2020
Topic :: Utilities
2121
Programming Language :: Python :: 3
22-
Programming Language :: Python :: 3.6
2322
Programming Language :: Python :: 3.7
2423
Programming Language :: Python :: 3.8
2524
Programming Language :: Python :: 3.9
25+
Programming Language :: Python :: 3.10
2626

2727
[options]
28-
python_requires = >=3.6
28+
python_requires = >=3.7
2929
install_requires =
3030
glob2
3131
Mako
3232
parse
3333
parse_type
3434
py
35-
pytest>=4.3
35+
pytest>=5.0
3636

3737
tests_require = tox
3838
packages = pytest_bdd

tests/feature/test_steps.py

+48
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,51 @@ def test_when_step_validation_error():
484484
result.assert_outcomes(failed=1)
485485
result.stdout.fnmatch_lines(["*test_when_step_validation_error*FAILED"])
486486
assert "INTERNALERROR" not in result.stdout.str()
487+
488+
489+
def test_steps_with_yield(testdir):
490+
"""Test that steps definition containing a yield statement work the same way as
491+
pytest fixture do, that is the code after the yield is executed during teardown."""
492+
493+
testdir.makefile(
494+
".feature",
495+
a="""\
496+
Feature: A feature
497+
498+
Scenario: A scenario
499+
When I setup stuff
500+
Then stuff should be 42
501+
""",
502+
)
503+
testdir.makepyfile(
504+
textwrap.dedent(
505+
"""\
506+
import pytest
507+
from pytest_bdd import given, when, then, scenarios
508+
509+
scenarios("a.feature")
510+
511+
@when("I setup stuff", target_fixture="stuff")
512+
def stuff():
513+
print("Setting up...")
514+
yield 42
515+
print("Tearing down...")
516+
517+
518+
@then("stuff should be 42")
519+
def check_stuff(stuff):
520+
assert stuff == 42
521+
print("Asserted stuff is 42")
522+
523+
"""
524+
)
525+
)
526+
result = testdir.runpytest("-s")
527+
result.assert_outcomes(passed=1)
528+
result.stdout.fnmatch_lines(
529+
[
530+
"*Setting up...*",
531+
"*Asserted stuff is 42*",
532+
"*Tearing down...*",
533+
]
534+
)

tests/scripts/test_generate.py

-3
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,6 @@ def test_unicode_characters(testdir, monkeypatch):
176176
),
177177
)
178178

179-
if sys.version_info < (3, 7):
180-
monkeypatch.setenv("PYTHONIOENCODING", "utf-8")
181-
182179
result = testdir.run("pytest-bdd", "generate", "unicode_characters.feature")
183180
expected_output = textwrap.dedent(
184181
'''\

tox.ini

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
[tox]
22
distshare = {homedir}/.tox/distshare
3-
envlist = py38-pytestlatest-linters,
4-
py39-pytest{43,44,45,46,50,51,52,53,54,60,61,62, latest}-coverage,
5-
py{36,37,38,310}-pytestlatest-coverage,
6-
py39-pytestlatest-xdist-coverage
3+
envlist = py310-pytestlatest-linters,
4+
; python 3.10 is only supported by pytest >= 6.2.5:
5+
py310-pytest{62,70,latest}-coverage,
6+
; the rest of pytest runs need to use an older python:
7+
py39-pytest{50,51,52,53,54,60,61}-coverage,
8+
py{37,38,39}-pytestlatest-coverage,
9+
py310-pytestlatest-xdist-coverage
710
skip_missing_interpreters = true
811

912
[testenv]
@@ -12,6 +15,7 @@ setenv =
1215
xdist: _PYTEST_MORE_ARGS=-n3 -rfsxX
1316
deps =
1417
pytestlatest: pytest
18+
pytest70: pytest~=7.0.0
1519
pytest62: pytest~=6.2.0
1620
pytest61: pytest~=6.1.0
1721
pytest60: pytest~=6.0.0
@@ -20,24 +24,18 @@ deps =
2024
pytest52: pytest~=5.2.0
2125
pytest51: pytest~=5.1.0
2226
pytest50: pytest~=5.0.0
23-
pytest46: pytest~=4.6.0
24-
pytest45: pytest~=4.5.0
25-
pytest44: pytest~=4.4.0
26-
pytest43: pytest~=4.3.0
2727

2828
coverage: coverage
2929
xdist: pytest-xdist
3030
-r{toxinidir}/requirements-testing.txt
3131
commands = {env:_PYTEST_CMD:pytest} {env:_PYTEST_MORE_ARGS:} {posargs:-vvl}
3232

33-
; Black doesn't support >py38 now
34-
[testenv:py38-pytestlatest-linters]
35-
deps = black
33+
[testenv:py310-pytestlatest-linters]
34+
deps = black==22.1.0
3635
commands = black --check --verbose setup.py docs pytest_bdd tests
3736

3837
[gh-actions]
3938
python =
40-
3.6: py36
4139
3.7: py37
4240
3.8: py38
4341
3.9: py39

0 commit comments

Comments
 (0)