python mocking function calls that are called during module import

I need to perform mocking for python code that is running during module import For example I have code like this import configparser config = configparser.ConfigParser() config.read(‘test.ini’) a = float(config[‘config’][‘a’]) b = float(config[‘config’][‘b’]) c = float(config[‘config’][‘c’]) print(a) print(b) print(c) I need mock “config” for testing import pytest import mock import app @mock.patch(‘app.configparser.ConfigParser’) def test_config_mock(config_mock): config_mock.return_value…

Details