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

Improve error message on unmatched method signature expectation #36

Merged
merged 1 commit into from Jul 19, 2021
Merged

Improve error message on unmatched method signature expectation #36

merged 1 commit into from Jul 19, 2021

Conversation

pglass
Copy link

@pglass pglass commented Feb 20, 2020

This is a small improvement to tell the user which expectations were not matched when a test fails. This makes it much easier for me to determine why a test has failed.

Before:

        ...
>       raise MethodSignatureError(_format_args(name, arguments))
E       flexmock.MethodSignatureError: foo(394272)

After:

        ...
>       raise MethodSignatureError(error_msg)
E       flexmock.MethodSignatureError: foo(18088)
E       Did not match expectation foo(2)
E       Did not match expectation foo(1)

Example code:

import random
import flexmock

def random_foo():
    Thing.foo(random.randint(10, 1000000))

class Thing(object):

    @staticmethod
    def foo(val):
        pass

def test_b():
    thing_mock = flexmock(Thing)
    thing_mock.should_call('foo').with_args(1).once()
    thing_mock.should_call('foo').with_args(2).once()

    random_foo()
    random_foo()

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 93.07% when pulling 641e212 on pglass:improve-error-msg into 131f0d5 on bkabrda:master.

Copy link
Member

@ollipa ollipa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Seems so work nicely 👍

@ollipa ollipa merged commit c102d71 into flexmock:master Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants