New submission from Adnan Umer <umr...@gmail.com>:

When a method/bounded function is mocked and side_effect is supplied to it, the 
side_effect function doesn't get the reference to the instance.

Suppose we have something like this


class SomeClass:
    def do_something(self, x):
        pass

def some_function(x):
    cls = SomeClass()
    y = class.do_something(x)
    return y


And the test for some_function will be 


def do_something_side_effect(x):
    retrun x

def test_some_function():
    with mock.path("SomeCass.do_something") as do_something_mock:
        do_something_mock.side_effect = do_something_side_effect
        assert some_function(1)


Here do_something_side_effect mock will not have access to SomeClass instance.

----------
components: Library (Lib)
messages: 332463
nosy: Adnan Umer
priority: normal
severity: normal
status: open
title: side_effect mocked method lose reference to instance
type: enhancement
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue35577>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to