Skip to content

Commit 2e94b4d

Browse files
committed
Merge branch 'pytest-dev:master' into master
2 parents caaf3d8 + 0f02d56 commit 2e94b4d

21 files changed

+285
-156
lines changed

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
charset = utf-8
11+
12+
[*.py]
13+
indent_style = space
14+
indent_size = 4
15+
16+
[*.yml]
17+
indent_style = space
18+
indent_size = 2

.github/workflows/main.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Main testing workflow
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.6", "3.7", "3.8", "3.9", 3.10.0-alpha.6]
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -U setuptools
26+
pip install tox tox-gh-actions codecov
27+
- name: Test with tox
28+
run: |
29+
tox
30+
codecov

.pre-commit-config.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
44
- repo: https://github.com/psf/black
5-
rev: 20.8b1
5+
rev: 21.4b0
66
hooks:
77
- id: black
88
- repo: https://github.com/pre-commit/pre-commit-hooks
9-
rev: v3.2.0
9+
rev: v3.4.0
1010
hooks:
1111
- id: trailing-whitespace
1212
- id: end-of-file-fixer
1313
- id: check-yaml
1414
- id: check-added-large-files
15+
- repo: https://github.com/asottile/pyupgrade
16+
rev: v2.13.0
17+
hooks:
18+
- id: pyupgrade
19+
args: [--py36-plus]

.travis.yml

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

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Changelog
44
Unreleased
55
-----------
66
- Drop compatibility for python 2 and officially support only python >= 3.6.
7+
- Fix error when using `--cucumber-json-expanded` in combination with `example_converters` (marcbrossaissogeti).
8+
- Fix `--generate-missing` not correctly recognizing steps with parsers
79

810
4.0.2
911
-----

pytest_bdd/cucumber_json.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def unconfigure(config):
4444
config.pluginmanager.unregister(xml)
4545

4646

47-
class LogBDDCucumberJSON(object):
47+
class LogBDDCucumberJSON:
4848

4949
"""Logging plugin for cucumber like json output."""
5050

@@ -90,7 +90,7 @@ def _serialize_tags(self, item):
9090

9191
def _format_name(self, name, keys, values):
9292
for param, value in zip(keys, values):
93-
name = name.replace("<{}>".format(param), value)
93+
name = name.replace(f"<{param}>", str(value))
9494
return name
9595

9696
def _format_step_name(self, report, step):

pytest_bdd/generation.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def print_missing_code(scenarios, steps):
102102
tw.line()
103103

104104
features = sorted(
105-
set(scenario.feature for scenario in scenarios), key=lambda feature: feature.name or feature.filename
105+
{scenario.feature for scenario in scenarios}, key=lambda feature: feature.name or feature.filename
106106
)
107107
code = generate_code(features, scenarios, steps)
108108
tw.write(code)
@@ -116,14 +116,16 @@ def _find_step_fixturedef(fixturemanager, item, name, type_):
116116
117117
:return: Step function.
118118
"""
119-
fixturedefs = fixturemanager.getfixturedefs(get_step_fixture_name(name, type_), item.nodeid)
120-
if not fixturedefs:
121-
name = find_argumented_step_fixture_name(name, type_, fixturemanager)
122-
if name:
123-
return _find_step_fixturedef(fixturemanager, item, name, type_)
124-
else:
119+
step_fixture_name = get_step_fixture_name(name, type_)
120+
fixturedefs = fixturemanager.getfixturedefs(step_fixture_name, item.nodeid)
121+
if fixturedefs is not None:
125122
return fixturedefs
126123

124+
argumented_step_name = find_argumented_step_fixture_name(name, type_, fixturemanager)
125+
if argumented_step_name is not None:
126+
return fixturemanager.getfixturedefs(argumented_step_name, item.nodeid)
127+
return None
128+
127129

128130
def parse_feature_files(paths, **kwargs):
129131
"""Parse feature files of given paths.

pytest_bdd/parser.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def parse_feature(basedir, filename, encoding="utf-8"):
101101
multiline_step = False
102102
prev_line = None
103103

104-
with io.open(abs_filename, "rt", encoding=encoding) as f:
104+
with open(abs_filename, encoding=encoding) as f:
105105
content = f.read()
106106

107107
for line_number, line in enumerate(content.splitlines(), start=1):
@@ -170,14 +170,14 @@ def parse_feature(basedir, filename, encoding="utf-8"):
170170
except exceptions.ExamplesNotValidError as exc:
171171
if scenario:
172172
raise exceptions.FeatureError(
173-
"""Scenario has not valid examples. {0}""".format(exc.args[0]),
173+
f"Scenario has not valid examples. {exc.args[0]}",
174174
line_number,
175175
clean_line,
176176
filename,
177177
)
178178
else:
179179
raise exceptions.FeatureError(
180-
"""Feature has not valid examples. {0}""".format(exc.args[0]),
180+
f"Feature has not valid examples. {exc.args[0]}",
181181
line_number,
182182
clean_line,
183183
filename,
@@ -195,7 +195,7 @@ def parse_feature(basedir, filename, encoding="utf-8"):
195195
return feature
196196

197197

198-
class Feature(object):
198+
class Feature:
199199
"""Feature."""
200200

201201
def __init__(self, scenarios, filename, rel_filename, name, tags, examples, background, line_number, description):
@@ -213,7 +213,7 @@ def __init__(self, scenarios, filename, rel_filename, name, tags, examples, back
213213
self.background = background
214214

215215

216-
class Scenario(object):
216+
class Scenario:
217217

218218
"""Scenario."""
219219

@@ -283,14 +283,14 @@ def validate(self):
283283
example_params = self.get_example_params()
284284
if params and example_params and params != example_params:
285285
raise exceptions.ScenarioExamplesNotValidError(
286-
"""Scenario "{0}" in the feature "{1}" has not valid examples. """
287-
"""Set of step parameters {2} should match set of example values {3}.""".format(
286+
"""Scenario "{}" in the feature "{}" has not valid examples. """
287+
"""Set of step parameters {} should match set of example values {}.""".format(
288288
self.name, self.feature.filename, sorted(params), sorted(example_params)
289289
)
290290
)
291291

292292

293-
class Step(object):
293+
class Step:
294294

295295
"""Step."""
296296

@@ -345,15 +345,15 @@ def name(self, value):
345345

346346
def __str__(self):
347347
"""Full step name including the type."""
348-
return '{type} "{name}"'.format(type=self.type.capitalize(), name=self.name)
348+
return f'{self.type.capitalize()} "{self.name}"'
349349

350350
@property
351351
def params(self):
352352
"""Get step params."""
353353
return tuple(frozenset(STEP_PARAM_RE.findall(self.name)))
354354

355355

356-
class Background(object):
356+
class Background:
357357

358358
"""Background."""
359359

@@ -373,7 +373,7 @@ def add_step(self, step):
373373
self.steps.append(step)
374374

375375

376-
class Examples(object):
376+
class Examples:
377377

378378
"""Example table."""
379379

@@ -407,7 +407,7 @@ def add_example_row(self, param, values):
407407
"""
408408
if param in self.example_params:
409409
raise exceptions.ExamplesNotValidError(
410-
"""Example rows should contain unique parameters. "{0}" appeared more than once""".format(param)
410+
f"""Example rows should contain unique parameters. "{param}" appeared more than once"""
411411
)
412412
self.example_params.append(param)
413413
self.vertical_examples.append(values)
@@ -454,7 +454,7 @@ def get_tags(line):
454454
"""
455455
if not line or not line.strip().startswith("@"):
456456
return set()
457-
return set((tag.lstrip("@") for tag in line.strip().split(" @") if len(tag) > 1))
457+
return {tag.lstrip("@") for tag in line.strip().split(" @") if len(tag) > 1}
458458

459459

460460
STEP_PARAM_RE = re.compile(r"\<(.+?)\>")

pytest_bdd/parsers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Step parsers."""
22

3-
from __future__ import absolute_import
43

54
import re as base_re
65
from functools import partial
@@ -9,7 +8,7 @@
98
from parse_type import cfparse as base_cfparse
109

1110

12-
class StepParser(object):
11+
class StepParser:
1312
"""Parser of the individual step."""
1413

1514
def __init__(self, name):
@@ -32,7 +31,7 @@ class re(StepParser):
3231

3332
def __init__(self, name, *args, **kwargs):
3433
"""Compile regex."""
35-
super(re, self).__init__(name)
34+
super().__init__(name)
3635
self.regex = base_re.compile(self.name, *args, **kwargs)
3736

3837
def parse_arguments(self, name):
@@ -52,7 +51,7 @@ class parse(StepParser):
5251

5352
def __init__(self, name, *args, **kwargs):
5453
"""Compile parse expression."""
55-
super(parse, self).__init__(name)
54+
super().__init__(name)
5655
self.parser = base_parse.compile(self.name, *args, **kwargs)
5756

5857
def parse_arguments(self, name):

pytest_bdd/reporting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .utils import get_parametrize_markers_args
1010

1111

12-
class StepReport(object):
12+
class StepReport:
1313
"""Step excecution report."""
1414

1515
failed = False
@@ -59,7 +59,7 @@ def duration(self):
5959
return self.stopped - self.started
6060

6161

62-
class ScenarioReport(object):
62+
class ScenarioReport:
6363
"""Scenario execution report."""
6464

6565
def __init__(self, scenario, node):

0 commit comments

Comments
 (0)