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

Failures when calling class/static method directly on derived class (not on instance) #72

Closed
adam-sikora opened this issue Aug 23, 2021 · 3 comments
Assignees
Labels

Comments

@adam-sikora
Copy link
Contributor

I have encountered multiple flexmock fails when mocking class/static methods that are called directly on a derived class. The issues started happening in 0.10.5 and are still present in 0.10.7. Tests to reproduce the failures:

class A:

    @classmethod
    def class_method(cls):
        return 1

    @staticmethod
    def static_method():
        return 1

    @classmethod
    def with_arg(cls, integer):
        return integer

    @staticmethod
    def with_arg_static(integer):
        return integer


class B(A):
    pass


def test_class_method_on_derived_class():
    flexmock(A).should_receive('class_method').and_return(1)
    # passes
    A.class_method()

    flexmock(B).should_receive('class_method').and_return(1)
    # passes
    B().class_method()

    # fails with:
    # TypeError: mock_method() missing 1 required positional argument: 'runtime_self'
    B.class_method()


def test_static_method_on_derived_class():
    flexmock(A).should_receive('static_method').and_return(1)
    # passes
    A.static_method()

    flexmock(B).should_receive('static_method').and_return(1)
    # passes
    B().static_method()

    # fails with:
    # TypeError: mock_method() missing 1 required positional argument: 'runtime_self'
    B.static_method()


def test_class_method_with_args_on_derived_class():
    flexmock(A).should_receive('with_arg').with_args(1).and_return(1)
    # passes
    A.with_arg(1)

    flexmock(B).should_receive('with_arg').with_args(1).and_return(1)
    # passes
    B().with_arg(1)

    # fails with:
    # flexmock.MethodSignatureError: get_one()
    # Did not match expectation get_one(1)
    B.with_arg(1)


def test_static_method_with_args_on_derived_class():
    flexmock(A).should_receive('with_arg_static').with_args(1).and_return(1)
    # passes
    A.with_arg_static(1)

    flexmock(B).should_receive('with_arg_static').with_args(1).and_return(1)
    # passes
    B().with_arg_static(1)

    # fails with:
    # flexmock.MethodSignatureError: with_arg_static()
    # Did not match expectation with_arg_static(1)
    B.with_arg_static(1)
@christophe-riolo
Copy link
Contributor

christophe-riolo commented Aug 23, 2021

I can reproduce this issue all the way from 0.7.0.
When testing with Pytest, however, before 0.10.5 I had a failure about the durations. Did you run your tests with Pytest ?
In any case, there is a bug to solve here thanks !

My bad, I did not test properly, and I can reproduce, I'll investigate

@ollipa
Copy link
Member

ollipa commented Aug 24, 2021

@christophe-riolo, I wrote tests to our test suite here: #76

You can use those tests to verify your fix.

@ollipa
Copy link
Member

ollipa commented Sep 4, 2021

Closed by #76 and #77

@ollipa ollipa closed this as completed Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants