pytest-bdd icon indicating copy to clipboard operation
pytest-bdd copied to clipboard

It's not possible to disable "argument is a fixture" behavior (pytest-bdd + unittest.mock)

Open psxvoid opened this issue 6 years ago • 1 comments
trafficstars

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

psxvoid avatar Sep 20 '19 05:09 psxvoid

I faced the same issue using patch() as a decorator, but you could use patch() as a Context Manager to circumvent the problem.

Refer to this article to understand how.

subhashb avatar Mar 22 '20 21:03 subhashb