qin / pymox

Automatically exported from code.google.com/p/pymox
Apache License 2.0
0 stars 0 forks source link

CreateMockAnything() should not allow attribute getting for unknown attributes in replay mode #25

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently the following works:

-----
m = mox.Mox()
obj = m.CreateMockAnything()
m.ReplayAll()
print obj.f

-----

This hides many bugs when doing unit testing, because attribute accesses to 
'forbidden' or nonexistent attributes is not spotted. 

As to the obvious solution of using CreateMock() instead of 
CreateMockAnything(), it's not applicable in some cases, like unit-testing a 
piece of code before the objects with which it interacts have been developed.

My suggestion is to cause such attribute access fail with 
UnexpectedAttributeAccess exception or something similar. Of course this will 
slightly modify the current behavior, according to which the exception is only 
thrown when 'f' gets called.

Original issue reported on code.google.com by vmal...@gmail.com on 4 Jul 2010 at 2:15

GoogleCodeExporter commented 9 years ago
Attribute access is not handled through __getattr__, so the current 
implementation doesn't intercept those calls.

It may be possible to re-impelement mox using __getattribute__, which would 
probably be much more powerful, but I don't have the bandwidth to do it at this 
time.

Original comment by steve.mi...@gmail.com on 7 Jul 2010 at 5:52