Skip to content

Commit f2e0ee3

Browse files
Use ruff lint.extend-select to keep ruff's default rules
Ruff 0.16 enables a much larger default rule set. 'lint.select' was replacing it entirely; 'lint.extend-select' keeps the defaults and adds our own selection on top. Fix the new violations: - RUF022: sort __all__ - RUF046: drop redundant int() around math.floor() - RUF059: use _ for unused unpacked variables - PLW0127: remove self-assignment of scenario_name - TRY002: raise pytest.UsageError instead of a bare Exception for gherkin-terminal-reporter incompatibilities
1 parent f67096a commit f2e0ee3

10 files changed

Lines changed: 11 additions & 10 deletions

File tree

‎CHANGES.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Changed
1616
+++++++
1717
* Relaxed `gherkin-official` dependency requirement to `>=29.0.0` to allow for newer versions of the `gherkin-official` package.
1818
* Excluded `gherkin-official` `31.0.0` and `32.0.0`, which crash with ``StopIteration`` when parsing empty descriptions (fixed upstream in `32.0.1`).
19+
* The ``--gherkin-terminal-reporter`` incompatibility errors (with another terminal reporter or with ``xdist``) are now raised as ``pytest.UsageError`` instead of a bare ``Exception``.
1920

2021
Deprecated
2122
++++++++++

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ build-backend = "uv_build"
7676

7777
[tool.ruff]
7878
line-length = 120
79-
lint.select = [
79+
lint.extend-select = [
8080
"B", # flake8-bugbear
8181
"BLE", # flake8-blind-except
8282
"C4", # flake8-comprehensions

‎src/pytest_bdd/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
from pytest_bdd.scenario import scenario, scenarios
66
from pytest_bdd.steps import given, step, then, when
77

8-
__all__ = ["given", "when", "step", "then", "scenario", "scenarios"]
8+
__all__ = ["given", "scenario", "scenarios", "step", "then", "when"]

‎src/pytest_bdd/cucumber_json.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def _get_result(self, step: StepReportDict, report: TestReport, error_message: b
124124
status = "skipped"
125125
else:
126126
raise ValueError(f"Unknown test outcome {report.outcome}")
127-
res: ResultElementDict = {"status": status, "duration": int(math.floor((10**9) * step["duration"]))} # nanosec
127+
res: ResultElementDict = {"status": status, "duration": math.floor((10**9) * step["duration"])} # nanosec
128128
if res_message is not None:
129129
res["error_message"] = res_message
130130
return res

‎src/pytest_bdd/generation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def _show_missing_code_main(config: Config, session: Session) -> None:
187187
session.exitstatus = 100
188188
return
189189

190-
features, scenarios, steps = parse_feature_files(config.option.features)
190+
_, scenarios, steps = parse_feature_files(config.option.features)
191191

192192
for item in session.items:
193193
if not isinstance(item, Function):

‎src/pytest_bdd/gherkin_terminal_reporter.py‎

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

33
import typing
44

5+
import pytest
56
from _pytest.terminal import TerminalReporter
67

78
from .reporting import test_report_context_registry
@@ -28,7 +29,7 @@ def configure(config: Config) -> None:
2829
# Get the standard terminal reporter plugin and replace it with our
2930
current_reporter = config.pluginmanager.getplugin("terminalreporter")
3031
if current_reporter.__class__ != TerminalReporter:
31-
raise Exception(
32+
raise pytest.UsageError(
3233
"gherkin-terminal-reporter is not compatible with any other terminal reporter."
3334
"You can use only one terminal reporter."
3435
f"Currently '{current_reporter.__class__}' is used."
@@ -39,7 +40,7 @@ def configure(config: Config) -> None:
3940
config.pluginmanager.unregister(current_reporter)
4041
config.pluginmanager.register(gherkin_reporter, "terminalreporter")
4142
if config.pluginmanager.getplugin("dsession"):
42-
raise Exception("gherkin-terminal-reporter is not compatible with 'xdist' plugin.")
43+
raise pytest.UsageError("gherkin-terminal-reporter is not compatible with 'xdist' plugin.")
4344

4445

4546
class GherkinTerminalReporter(TerminalReporter): # type: ignore[misc]

‎src/pytest_bdd/scenario.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ def scenario(
372372
:param features_base_dir: Optional base dir location for locating feature files. If not set, it will try and resolve using property set in .ini file, then the caller_module_path.
373373
"""
374374
__tracebackhide__ = True
375-
scenario_name = scenario_name
376375
caller_module_path = get_caller_module_path()
377376

378377
# Get the feature

‎tests/scripts/test_generate.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_generate(pytester, monkeypatch, capsys):
3535

3636
monkeypatch.setattr(sys, "argv", ["", "generate", str(feature)])
3737
main()
38-
out, err = capsys.readouterr()
38+
out, _ = capsys.readouterr()
3939
assert out == textwrap.dedent(
4040
'''\
4141
"""Code generation feature tests."""

‎tests/scripts/test_main.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_main(monkeypatch, capsys):
1616
monkeypatch.setattr(sys, "argv", ["pytest-bdd"])
1717
monkeypatch.setattr(sys, "exit", lambda x: x)
1818
main()
19-
out, err = capsys.readouterr()
19+
_, err = capsys.readouterr()
2020
assert "usage: pytest-bdd [-h]" in err
2121
assert "pytest-bdd: error:" in err
2222

‎tests/scripts/test_migrate.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_migrate(monkeypatch, capsys, pytester):
2828

2929
monkeypatch.setattr(sys, "argv", ["", "migrate", str(tests)])
3030
main()
31-
out, err = capsys.readouterr()
31+
out, _ = capsys.readouterr()
3232
out = "\n".join(sorted(out.splitlines()))
3333
expected = textwrap.dedent(
3434
"""

0 commit comments

Comments
 (0)