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

Cannot stub a whole class #16

Open jonathan-benn opened 7 years ago

jonathan-benn commented 7 years ago
class C():
    def f2(self, x):
        return x*2
    def f3(self, x):
        return x*3
c = C()
stub = sinon.stub(c) # raises exception
note35 commented 7 years ago

This feature is not exist in previous version I remember. I have tried to implement this at first, but later I found this feature is not exist in SinonJS old version, thus I skipped it.

What I tried to implement this is used deepcopy whole module before, and it didn't work. Also, I have asked this question on StackOverflow before - https://stackoverflow.com/questions/40283493/how-to-deepcopy-a-module-in-python

I believe this should be a low priority issue, since the effort might be too big by implementing own deepcopy.

stub.__init__ -> module -> deepcopy -> replace all module's function
stub.restore -> replace all module's function again from deepcopy

Do you have any idea about this?

jonathan-benn commented 7 years ago

This one isn't a very important feature of Sinon.JS, since the author recommends that you only stub one method at a time, as is already supported by Sinon.PY