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

Base class call count when spying is inconsistent with mocking #80

Open
ollipa opened this issue Sep 4, 2021 · 0 comments
Open

Base class call count when spying is inconsistent with mocking #80

ollipa opened this issue Sep 4, 2021 · 0 comments
Labels

Comments

@ollipa
Copy link
Member

ollipa commented Sep 4, 2021

Spying base class with should_call counts calls to subclasses and instances of subclasses when a subclass has it's own spy set. I think here the functionality should be consistent with mocking. If the child has has it's own spy, then the spy in the base class, should not count calls to the child class.

Example code with should_call:

def test_spy_static_method_on_derived_class_after_spying_base_class():
    flexmock(SomeClass).should_call("static_method").and_return("static_method").once()
    assert SomeClass.static_method() == "static_method"
    flexmock(DerivedClass).should_call("static_method").and_return("static_method").twice()
    assert DerivedClass().static_method() == "static_method"
    assert DerivedClass.static_method() == "static_method"

Raises:

flexmock.exceptions.MethodCallError: static_method() expected to be called exactly 1 time, called 2 times

Similar test with should_receive passes:

def test_mock_static_method_on_derived_class_after_mocking_base_class():
    flexmock(SomeClass).should_receive("static_method").and_return(3).once()
    assert SomeClass.static_method() == 3
    flexmock(DerivedClass).should_receive("static_method").and_return(4).twice()
    assert DerivedClass().static_method() == 4
    assert DerivedClass.static_method() == 4
@ollipa ollipa added the bug label 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

1 participant