Skip to content

Commit cf679a9

Browse files
authored
Merge pull request #649 from pytest-dev/sourcery/master
Sourcery refactored master branch
2 parents fead99d + f1ba44c commit cf679a9

File tree

5 files changed

+10
-15
lines changed

5 files changed

+10
-15
lines changed

src/pytest_bdd/cucumber_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _get_result(self, step: dict[str, Any], report: TestReport, error_message: b
6464
result: dict[str, Any] = {}
6565
if report.passed or not step["failed"]: # ignore setup/teardown
6666
result = {"status": "passed"}
67-
elif report.failed and step["failed"]:
67+
elif report.failed:
6868
result = {"status": "failed", "error_message": str(report.longrepr) if error_message else ""}
6969
elif report.skipped:
7070
result = {"status": "skipped"}

src/pytest_bdd/generation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ def _show_missing_code_main(config: Config, session: Session) -> None:
179179
features, scenarios, steps = parse_feature_files(config.option.features)
180180

181181
for item in session.items:
182-
scenario = getattr(item.obj, "__scenario__", None)
183-
if scenario:
182+
if scenario := getattr(item.obj, "__scenario__", None):
184183
if scenario in scenarios:
185184
scenarios.remove(scenario)
186185
for step in scenario.steps:

src/pytest_bdd/gherkin_terminal_reporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def pytest_runtest_logreport(self, report: TestReport) -> Any:
9090
self._tw.write("\n")
9191
for step in report.scenario["steps"]:
9292
self._tw.write(f" {step['keyword']} {step['name']}\n", **scenario_markup)
93-
self._tw.write(" " + word, **word_markup)
93+
self._tw.write(f" {word}", **word_markup)
9494
self._tw.write("\n\n")
9595

9696
self.stats.setdefault(cat, []).append(rep)

src/pytest_bdd/parser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ def strip_comments(line: str) -> str:
6565
6666
:return: Stripped line.
6767
"""
68-
res = COMMENT_RE.search(line)
69-
if res:
68+
if res := COMMENT_RE.search(line):
7069
line = line[: res.start()]
7170
return line.strip()
7271

@@ -189,7 +188,7 @@ def parse_feature(basedir: str, filename: str, encoding: str = "utf-8") -> Featu
189188
scenario.examples.set_param_names([l for l in split_line(parsed_line) if l])
190189
mode = types.EXAMPLE_LINE
191190
elif mode == types.EXAMPLE_LINE:
192-
scenario.examples.add_example([l for l in split_line(stripped_line)])
191+
scenario.examples.add_example(list(split_line(stripped_line)))
193192
elif mode and mode not in (types.FEATURE, types.TAG):
194193
step = Step(name=parsed_line, type=mode, indent=line_indent, line_number=line_number, keyword=keyword)
195194
if feature.background and not scenario:

src/pytest_bdd/scenario.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def find_fixturedefs_for_step(step: Step, fixturemanager: FixtureManager, nodeid
4646
"""Find the fixture defs that can parse a step."""
4747
# happens to be that _arg2fixturedefs is changed during the iteration so we use a copy
4848
fixture_def_by_name = list(fixturemanager._arg2fixturedefs.items())
49-
for i, (fixturename, fixturedefs) in enumerate(fixture_def_by_name):
49+
for fixturename, fixturedefs in fixture_def_by_name:
5050
for pos, fixturedef in enumerate(fixturedefs):
5151
step_func_context = getattr(fixturedef.func, "_pytest_bdd_step_context", None)
5252
if step_func_context is None:
@@ -244,14 +244,11 @@ def scenario_wrapper(request: FixtureRequest, _pytest_bdd_example: dict[str, str
244244
def collect_example_parametrizations(
245245
templated_scenario: ScenarioTemplate,
246246
) -> list[ParameterSet] | None:
247-
# We need to evaluate these iterators and store them as lists, otherwise
248-
# we won't be able to do the cartesian product later (the second iterator will be consumed)
249-
contexts = list(templated_scenario.examples.as_contexts())
250-
if not contexts:
247+
if contexts := list(templated_scenario.examples.as_contexts()):
248+
return [pytest.param(context, id="-".join(context.values())) for context in contexts]
249+
else:
251250
return None
252251

253-
return [pytest.param(context, id="-".join(context.values())) for context in contexts]
254-
255252

256253
def scenario(
257254
feature_name: str, scenario_name: str, encoding: str = "utf-8", features_base_dir=None
@@ -263,7 +260,7 @@ def scenario(
263260
:param str encoding: Feature file encoding.
264261
"""
265262
__tracebackhide__ = True
266-
scenario_name = str(scenario_name)
263+
scenario_name = scenario_name
267264
caller_module_path = get_caller_module_path()
268265

269266
# Get the feature

0 commit comments

Comments
 (0)