Proper way to return mocked object using pytest.fixture

The problem is that when the worker returns the scope of “with” statement ends making the object take its real value, the solution is to use “yield”.

@pytest.fixture()
def mocked_worker():
    with patch('test.test_module.os.getcwd', return_value="Testing"):
        result = Worker()
        yield result

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)