I have one class with a method that instantiates an element of a second class:
class FirstClass:
def method_one():
second_class = SecondClass()
the second class has a method with a default argument:
class SecondClass:
def method_two(important_date: datetime.date = get_today())
and a function get_today
in a different file date_service
:
def get_today() -> datetime.date:
return datetime.date.today()
I am testing method_one
in a test_first_class.py
and I don't manage to mock the value of get_today()
.
I looked at several pages and solutions in SO and I couldn't fix it. Some of the ideas:
- I tried that but in the line
with patch.object(build_url, 'func_defaults', ('domain',)):
I don't know what I have to put at build_url
. I tried something like SecondClass.method_two
and it doesn't work.
REMARK: I know that a good unit test should test FirstClass
and SecondClass
independently, and mock method_two
in test_first_class.py
but for some reasons I can't do that :-(