In conftest (in an autouse fixture):
monkeypatch.setattr('collector.util.download_data', lambda url:"Winning" )
In collector/util.py:
def download_data(url):
assert False
In the_caller.py:
from collector.util import download_data
def some_function():
download_data("blah")
When I call some_function(), I get the assert. However, if I change the_caller.py to:
import collector
def some_function():
collector.util.download_data("blah")
then I get "Winning".
Why is this behaving differently, and how can I make the monkeypatch work for both scenarios?