Skip to content

Inheriting from instantiated generic class causes mocking to fail #250

Closed
@jhance

Description

@jhance

My reproduction (python 2)

import mock

from typing import Generic, TypeVar

T = TypeVar('T')

class Bar(Generic[T]):
    def __init__(self):
        pass

    def do_bar(self):
        print("bar")

class Foo(Bar[int]):
    def do_foo(self):
        self.do_bar()

@mock.patch.object(Bar, 'do_bar')
def mocked(mock_do_bar):
    mock_do_bar.return_value = None
    foo = Foo()
    foo.do_foo()

mocked()

will unexpectedly print bar.

The inheritance here is crucial.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions