I have a project assigning 2 configs in my main __init__
file since they are used frequently throughout the project.
#__init__.py
from config import Config
config1 = Config('Email')
config2 = Config('Test')
My Config class within config.py has a method called content
that I need to mock out on instances config1
and config2
. The config does call out to a third party library to do an http request, so I need to return a json
dictionary for the response to content
.
In a validators function I have the following:
#validation.py
from parser import config1, config2
def validation(msg):
if "email" in config1.keys():
...
I'm not trying to mock out the tests but keep getting errors. I've tried various mock patch
paths but none work.
My latest attempt is the following:
from mock import patch
from parser import validation
@patch('parser.Config')
def test_is_valid(mock_config):
mock_config.return_value.content = "Test"
assert validation.is_valid("email") == True
What am I doing wrong that my instances of Config (config1, and config2) are not correctly returning the .content values? Thanks