Search code examples
mockingpytestbddpatch

Pytest bdd with mock patch?


Anyone have a working example of using pytest bdd with a mock.patch? Ie.


@when(I do this)
def do_this_thing():
   with mock.patch('myinnerfunc', return_value=False):
      myfunc()

So in above I would want to mock a function call myinnerfunc inside myfunc.

In my real example, it just does not mock the inner function


Solution

  • Doh, problem was that pytest_bdd with outlines passes what you think is a boolean True/False value as a string. Therefore the logic in my function which was returning True False as a boolean, was incorrectly interpreted as a string value yielding incorrect results.