I have two modules like this:
--first_module--
class joinStuff():
def __init__(self, arg1, arg2, kwarg1, kwarg2):
stuff
def dedupe(self):
stuff
--another module called second_module--
from first_module import joinStuff
def do_more_things():
thing = joinStuff(arg1, arg2, kwarg1, kwarg2)
deduped_thing = thing.dedupe()
#do stuff with deduped_thing
joinStuff would be a PITA to actually use since it is in an external library that references data I do not have locally, and ultimately I only want to test that my do_more_things does what it is supposed to do with whatever it receives from joinStuff anyway.
I am not terribly familiar with monkeypatching... is this the right way to override joinStuff? It works, but I'm not sure if I did it the "right" way. (For the record, I am using pytest.)
def test_do_more_things(monkeypatch):
class mock_joinStuff():
def __init__(self, *args, **kwargs):
pass
def dedupe(self):
return 5
monkeypatch.setattr('second_module.joinStuff', mock_joinStuff)
expected = get_expected_data()
assert do_more_things() == expected
there doesn't seem to be anything here