Python: Mock Patch Errors with Flask

前端 未结 1 1528
时光取名叫无心
时光取名叫无心 2021-01-25 12:29

I am a complete newb when it comes to writing Python, let alone testing it.

Here is my Flask endpoint:

@blueprint.route(\'/mailing_finish/

        
相关标签:
1条回答
  • 2021-01-25 13:16

    You imported sumall_redis as a local name in your view module, but mock the original sumall.utils.sumall_redis.

    You probably have this at the top of your view module:

    from sumall.utils import sumall_redis
    

    This binds that object to a local name in the module. When the test starts and the patch is applied, only the original sumall_redis object in the sumall.utils module will be affected, not this local name.

    You'll need to mock the name bound in your view module instead:

    @mock.patch('view_module.sumall_redis')
    

    This applies to your other 2 imports as well.

    The mock documentation includes a guide on where to patch that you might want to read.

    0 讨论(0)
提交回复
热议问题