Ignore mock patch arguments when resolving step fixtures#816
Open
lin-hongkuan wants to merge 1 commit into
Open
Ignore mock patch arguments when resolving step fixtures#816lin-hongkuan wants to merge 1 commit into
lin-hongkuan wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #330.
Summary
unittest.mock.patch()injects mock objects as positional arguments when the decorated function is called. Pytest accounts for that by ignoring those injected arguments while resolving fixtures, but pytest-bdd currently treats every required positional step parameter as a fixture dependency.That means a patched step like:
fails before execution with
fixture 'cwd_mock' not found.This updates pytest-bdd's required-argument helper to reuse pytest's
num_mock_patch_args()rule, so mock-provided arguments are skipped when resolving step fixtures. Normal fixture dependencies and parser-provided step arguments continue to work unchanged.Tests
.\.venv\Scripts\python.exe -m pytest tests/steps/test_common.py::test_step_function_accepts_unittest_mock_patch_argument -q.\.venv\Scripts\python.exe -m pytest tests/steps/test_common.py tests/args/parse/test_args.py tests/args/regex/test_args.py tests/args/cfparse/test_args.py -q-> 16 passed.\.venv\Scripts\python.exe -m pytest tests/feature/test_steps.py::test_step_hooks tests/feature/test_steps.py::test_step_trace -q-> 2 passed.\.venv\Scripts\ruff.exe check src/pytest_bdd/utils.py tests/steps/test_common.py.\.venv\Scripts\ruff.exe format --check src/pytest_bdd/utils.py tests/steps/test_common.py.\.venv\Scripts\mypy.exe src/pytest_bdd/utils.py-> no type issues; current mypy reports that this version no longer supports the repository's configuredpython_version = 3.9git diff --check