0

I want to write unit tests for the main.py class. The file structure of my project is like this,

enter image description here

my unit tests are included in test/source/code_files folder. I want to mock some methods in the main class too. (which uses variables in source/config/config.py) I'm using the patch for this.

ex:

import main
     @patch('main.config.retry_times')
     def test_method(self, mock_retry_times):
     mock_retry_times().return_value = 'retry_times_mock_val'
     #calling the main class method

in the main class method, retry_times is defined like this,

from source.config import config

    def method():
    var1 = config.retry_times['url']
    # Do other stuff

This gave me an error as,

enter image description here

I tried with Magic Mock object as well. But it didn't work as per this solution. My imports also work fine. But I figure out one thing. when I check mock IDs in both the testable class and the test class they were different like this.

enter image description here

It seems like an issue in these ids. I think they must be the same in both classes. Does anyone help me to sortout this issue.

chamzz.dot
  • 607
  • 2
  • 12
  • 24

0 Answers0