0

Let's say I have this situation:

module2.py

class Bar:

    def bar():
        a = 5
        # do stuff
         Messages.show("Done")

module1.py

import module2

class Foo:

    def __init__(self):
         self.bar = module2.Bar()
    def foo(self):
        self.bar.bar()

I want to test the method Foo.foo(), but I want to ignore Messages.show("Done), ie I want calls to the Messages.show function to be done on a mock object. If foo was calling Messages.show directly, I could use monkeypatch on foo to mock the Messages class. But now, I'm calling a class from another module and I don't know how to specify that Messages.show calls should not be done ( the reason being that they access the Gui and that doesn't work in a test environment). Let's assume I cannot modify module2.py.

1 Answer 1

2

Just override what module2 thinks Messages is:

import module2

module2.Messages = ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.