pytest-dev / pytest-dev/pytest-bdd
It's not possible to disable "argument is a fixture" behavior (pytest-bdd + unittest.mock)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 251
- Avg merge
- 43m
- Merged PRs (30d)
- 2
Description
Hi,
I'm trying to use pytest-bdd with unittest.mock - to be more precise - I have to patch a class (let's say 'MyClass') from a module_XXX in one of the steps. But the issues is that unittest.mock uses decorators to provide patched classes via method arguments. But pytest-bdd always considers arguments as fixtures and obviously cannot find them. Here is the code:
@then('it should call my class method_YYY')
@patch('module_XXX.MyClass')
def it_should_call_my_class_method_yyy(MyClassMock):
module_XXX.__init__("__main__")
assert MyClassMock.called
Is it possible to disable "argument is a fixture" pytest-bdd feature? Is pytest-bdd compatible with unittest.mock? It seems like, the documentation of pytest-bdd says nothing about such cases.
-Thanks
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No implementation file or test is named. Start by reproducing the pytest-bdd step shown with unittest.mock.patch, then inspect how step-function arguments are resolved as fixtures; done means the compatibility behavior is supported or the limitation is documented with a clear alternative.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100