Skip to content

Fix PytestWarning: usefixtures() without arguments when scenario has no fixture args#803

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-pytest-warning-python-3-13
Draft

Fix PytestWarning: usefixtures() without arguments when scenario has no fixture args#803
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-pytest-warning-python-3-13

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 5, 2026

pytest 9.x added a PytestWarning when usefixtures() is called with no arguments. This surfaced in pytest-bdd whenever a scenario function had no fixture arguments (e.g. test functions auto-generated by scenarios()), because pytest.mark.usefixtures(*func_args) was called unconditionally even with an empty func_args.

Changes

  • scenario.py: Guard the usefixtures mark application with if func_args: so it is only applied when there are actual fixture names to pass.
  • tests/feature/test_scenario.py: Add regression test test_no_usefixtures_warning_when_no_args that runs pytest with -W error::pytest.PytestWarning to confirm no spurious warning is emitted when using scenarios() with no-argument test functions.
# Before: always applied, even with func_args=[]
scenario_wrapper = pytest.mark.usefixtures(*func_args)(scenario_wrapper)

# After: only applied when there are fixture names
if func_args:
    scenario_wrapper = pytest.mark.usefixtures(*func_args)(scenario_wrapper)

Copilot AI changed the title [WIP] Fix PytestWarning for usefixtures in pytest-bdd Fix PytestWarning: usefixtures() without arguments when scenario has no fixture args Apr 5, 2026
Copilot AI requested a review from youtux April 5, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python 3.13 and pytest-bdd give "PytestWarning: usefixtures() in TESTNAME without arguments has no effect"

2 participants