How to Mock a Google API Library with Python 3.7 for Unit Testing

前端 未结 2 1825
感动是毒
感动是毒 2021-02-06 04:36

I\'m trying to create a set of Unit Tests to test the Google Client Library for Bigquery. I\'m struggling to make a Unittest file which will mock the client and will let me test

2条回答
  •  盖世英雄少女心
    2021-02-06 04:56

    I also find it hard to get around the authentication part and only mock interacting with methods, so I ended up just mocked the whole library. :facepalm:

    import sys
    
    from unittest.mock import MagicMock
    
    sys.modules["google.cloud.storage"] = MagicMock()
    
    from your_application import make_app
    
    
    def test_make_app():
        make_app()
    

提交回复
热议问题