Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy() does not play well with mock objects #26

Closed
fatuhoku opened this issue Sep 5, 2013 · 3 comments
Closed

proxy() does not play well with mock objects #26

fatuhoku opened this issue Sep 5, 2013 · 3 comments
Assignees
Milestone

Comments

@fatuhoku
Copy link

fatuhoku commented Sep 5, 2013

Execution completely freezes up when trying to get a proxy of an actor that's got a bit of constructor injection going on.

I'm specifically using Voidspace mock's MagicMock object:

# ...
mock_credit_card_processor = MagicMock()
foobar = Foobar.start(mock_credit_card_processor)
foobar.proxy()       # blocked indefinitely here!
# ...

... where the code to Foobar looks something like this:

class FooBar(pykka.ThreadingActor):
    def __init__(self, credit_card_processor):
        super(FooBar, self).__init__()
        self.credit_card_processor = credit_card_processor

I suspect because mock objects don't behave as pykka expects members to behave when doing introspection.

@jodal
Copy link
Owner

jodal commented Sep 5, 2013

Yeah, there's a conflict between mock trying to please everything and provide any attribute asked for, and Pykka's proxy introspecting to figure out what attributes and methods are available. I haven't looked deeply into how to make them work better together, but I found a workaround: if you give your mock the real implementation as a spec then the mock object will only say it has attributes that the real implementation has as well, and not everything asked for.

To update your example:

# ...
mock_credit_card_processor = MagicMock(spec=RealCreditCardProcessor)
foobar = Foobar.start(mock_credit_card_processor, msg_captor)
foobar.proxy()
# ...

@fatuhoku
Copy link
Author

fatuhoku commented Sep 6, 2013

Awesome, that's got me up and running again. Thanks @jodal .

@jodal
Copy link
Owner

jodal commented Sep 6, 2013

I'll leave this open as a reminder to include it in a section on testing Pykka code.

@jodal jodal added this to the v2.0 milestone Jan 29, 2019
@jodal jodal self-assigned this Feb 8, 2019
@jodal jodal closed this as completed in dce57bd Feb 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants