-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #649
Conversation
elif report.failed and step["failed"]: | ||
elif report.failed: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function LogBDDCucumberJSON._get_result
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
src/pytest_bdd/generation.py
Outdated
if config.option.generate_missing: | ||
return show_missing_code(config) | ||
return None # Make mypy happy | ||
return show_missing_code(config) if config.option.generate_missing else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cmdline_main
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
This removes the following comments ( why? ):
# Make mypy happy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undo this
src/pytest_bdd/generation.py
Outdated
scenario = getattr(item.obj, "__scenario__", None) | ||
if scenario: | ||
if scenario := getattr(item.obj, "__scenario__", None): | ||
if scenario in scenarios: | ||
scenarios.remove(scenario) | ||
for step in scenario.steps: | ||
fixturedefs = _find_step_fixturedef(fm, item, step=step) | ||
if fixturedefs: | ||
if fixturedefs := _find_step_fixturedef(fm, item, step=step): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _show_missing_code_main
refactored with the following changes:
- Use named expression to simplify assignment and conditional [×2] (
use-named-expression
)
else: | ||
if rep.passed: | ||
word_markup = {"green": True} | ||
elif rep.failed: | ||
word_markup = {"red": True} | ||
elif rep.skipped: | ||
word_markup = {"yellow": True} | ||
elif rep.passed: | ||
word_markup = {"green": True} | ||
elif rep.failed: | ||
word_markup = {"red": True} | ||
elif rep.skipped: | ||
word_markup = {"yellow": True} | ||
feature_markup = {"blue": True} | ||
scenario_markup = word_markup | ||
|
||
if self.verbosity <= 0: | ||
if ( | ||
self.verbosity > 0 | ||
and self.verbosity == 1 | ||
and hasattr(report, "scenario") | ||
): | ||
self.ensure_newline() | ||
self._tw.write("Feature: ", **feature_markup) | ||
self._tw.write(report.scenario["feature"]["name"], **feature_markup) | ||
self._tw.write("\n") | ||
self._tw.write(" Scenario: ", **scenario_markup) | ||
self._tw.write(report.scenario["name"], **scenario_markup) | ||
self._tw.write(" ") | ||
self._tw.write(word, **word_markup) | ||
self._tw.write("\n") | ||
elif ( | ||
self.verbosity > 0 | ||
and self.verbosity == 1 | ||
or self.verbosity > 0 | ||
and self.verbosity > 1 | ||
and not hasattr(report, "scenario") | ||
or self.verbosity <= 0 | ||
): | ||
return super().pytest_runtest_logreport(rep) | ||
elif self.verbosity == 1: | ||
if hasattr(report, "scenario"): | ||
self.ensure_newline() | ||
self._tw.write("Feature: ", **feature_markup) | ||
self._tw.write(report.scenario["feature"]["name"], **feature_markup) | ||
self._tw.write("\n") | ||
self._tw.write(" Scenario: ", **scenario_markup) | ||
self._tw.write(report.scenario["name"], **scenario_markup) | ||
self._tw.write(" ") | ||
self._tw.write(word, **word_markup) | ||
self._tw.write("\n") | ||
else: | ||
return super().pytest_runtest_logreport(rep) | ||
elif self.verbosity > 1: | ||
if hasattr(report, "scenario"): | ||
self.ensure_newline() | ||
self._tw.write("Feature: ", **feature_markup) | ||
self._tw.write(report.scenario["feature"]["name"], **feature_markup) | ||
self._tw.write("\n") | ||
self._tw.write(" Scenario: ", **scenario_markup) | ||
self._tw.write(report.scenario["name"], **scenario_markup) | ||
self._tw.write("\n") | ||
for step in report.scenario["steps"]: | ||
self._tw.write(f" {step['keyword']} {step['name']}\n", **scenario_markup) | ||
self._tw.write(" " + word, **word_markup) | ||
self._tw.write("\n\n") | ||
else: | ||
return super().pytest_runtest_logreport(rep) | ||
self.ensure_newline() | ||
self._tw.write("Feature: ", **feature_markup) | ||
self._tw.write(report.scenario["feature"]["name"], **feature_markup) | ||
self._tw.write("\n") | ||
self._tw.write(" Scenario: ", **scenario_markup) | ||
self._tw.write(report.scenario["name"], **scenario_markup) | ||
self._tw.write("\n") | ||
for step in report.scenario["steps"]: | ||
self._tw.write(f" {step['keyword']} {step['name']}\n", **scenario_markup) | ||
self._tw.write(f" {word}", **word_markup) | ||
self._tw.write("\n\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GherkinTerminalReporter.pytest_runtest_logreport
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
) - Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Remove redundant conditional [×2] (
remove-redundant-if
)
src/pytest_bdd/parser.py
Outdated
for prefix, _ in STEP_PREFIXES: | ||
if line.startswith(prefix): | ||
return prefix.strip(), line[len(prefix) :].strip() | ||
return "", line | ||
return next( | ||
( | ||
(prefix.strip(), line[len(prefix) :].strip()) | ||
for prefix, _ in STEP_PREFIXES | ||
if line.startswith(prefix) | ||
), | ||
("", line), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function parse_line
refactored with the following changes:
- Use the built-in function
next
instead of a for-loop (use-next
)
src/pytest_bdd/parsers.py
Outdated
if isinstance(step_name, StepParser): | ||
return step_name | ||
|
||
return string(step_name) | ||
return step_name if isinstance(step_name, StepParser) else string(step_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_parser
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
src/pytest_bdd/reporting.py
Outdated
if self.stopped is None: | ||
return 0 | ||
|
||
return self.stopped - self.started | ||
return 0 if self.stopped is None else self.stopped - self.started |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function StepReport.duration
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
for i, (fixturename, fixturedefs) in enumerate(fixture_def_by_name): | ||
for fixturename, fixturedefs in fixture_def_by_name: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function find_fixturedefs_for_step
refactored with the following changes:
- Remove unnecessary calls to
enumerate
when the index is not used (remove-unused-enumerate
)
# We need to evaluate these iterators and store them as lists, otherwise | ||
# we won't be able to do the cartesian product later (the second iterator will be consumed) | ||
contexts = list(templated_scenario.examples.as_contexts()) | ||
if not contexts: | ||
if contexts := list(templated_scenario.examples.as_contexts()): | ||
return [pytest.param(context, id="-".join(context.values())) for context in contexts] | ||
else: | ||
return None | ||
|
||
return [pytest.param(context, id="-".join(context.values())) for context in contexts] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function collect_example_parametrizations
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Lift code into else after jump in control flow (
reintroduce-else
) - Swap if/else branches (
swap-if-else-branches
)
This removes the following comments ( why? ):
# We need to evaluate these iterators and store them as lists, otherwise
# we won't be able to do the cartesian product later (the second iterator will be consumed)
scenario_name = str(scenario_name) | ||
scenario_name = scenario_name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function scenario
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #649 +/- ##
==========================================
- Coverage 95.56% 95.56% -0.01%
==========================================
Files 49 49
Lines 1783 1780 -3
Branches 194 193 -1
==========================================
- Hits 1704 1701 -3
Misses 52 52
Partials 27 27
☔ View full report in Codecov by Sentry. |
39a7aa7
to
f1ba44c
Compare
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run:Help us improve this pull request!