This is a very simple example:
# my_func.py
from google.cloud import storage
storage_client = storage.Client()
def one():
return 1
# my_func_test.py
import unittest
from my_func import one, storage
from unittest import mock
class TestOne(unittest.TestCase):
@ mock.patch('my_func.storage')
def test_assert(self, mock_storage):
mock_bucket = mock.Mock()
mock_storage.Client.return_value = mock_bucket
result = one()
self.assertEqual(result, 1)
unittest.main()
Why running this test it returns "Project was not passed and could not be determined from the environment". But if I put the storage_client inside one(), it will pass all OK