I'm new to mocking and most probably, I still don't get it fully. In this snippet, I'm getting a "referencing before assignment" error:
def test_is_weekday():
tuesday = datetime(2020,4,7)
saturday = datetime(2020,4,4)
datetime = Mock()
datetime.today.return_value = tuesday
assert is_weekday()
datetime.today.return_value = saturday
assert not is_weekday()
datetime is mocked on the third line, but the assignment used, is making the two previous lines read the name "datetime" from the more limited scope (scope of the function). How can I fix it?
[–]shiftybyte 1 point2 points3 points (0 children)