note35 / sinon

Standalone and test framework agnostic Python test spies, stubs and mocks (pronounced "sigh-non").
BSD 2-Clause "Simplified" License
13 stars 4 forks source link

Get rid of target "dirty hack" #36

Open jonathan-benn opened 6 years ago

jonathan-benn commented 6 years ago

In Wrapper.py and stub.py there is a line # Todo: dirty hack related to the element conditions["target"]. This special case exists for when a new stub is created based on a class (as opposed to an object). We should find a way to remove this dirty hack.

note35 commented 6 years ago

Here is the proper way for binding self with replaced function.

def bind(instance, func, as_name):
    '''bind self into instance'''
    setattr(instance, as_name, func.__get__(instance, instance.__class__))
jonathan-benn commented 6 years ago

It's worth a try. :)