tag:blogger.com,1999:blog-27854051.post1726627966695223894..comments2024-03-21T18:51:18.504+02:00Comments on PythonWise: Super Simple MockingMiki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-27854051.post-28574300614106596082020-02-26T04:07:13.260+02:002020-02-26T04:07:13.260+02:00Thanks for sharing, nice post! Post really provice...Thanks for sharing, nice post! Post really provice useful information!<br /><br />Giaonhan247 chuyên dịch vụ <a href="http://www.google.kz/url?q=https://giaonhan247.vn/bang-gia-cuoc-ship-van-chuyen-gui-hang-tu-viet-nam-di-my-gia-re.html" rel="nofollow">vận chuyển hàng đi mỹ</a> cũng như dịch vụ <a href="http://www.google.com.mt/url?q=https://giaonhan247.vn/ship-hang-my.html" rel="nofollow">ship hàng mỹ</a> từ dịch vụ nhận mua hộ hàng mỹ từ trang <a href="https://images.google.se/url?q=https://giaonhan247.vn/mua-hang-tren-ebay.html" rel="nofollow">ebay vn</a> cùng với dịch vụ <a href="http://www.google.tn/url?q=https://giaonhan247.vn/cach-mua-hang-tren-amazon.html" rel="nofollow">mua hàng amazon</a> về VN uy tín, giá rẻ.thulannguyenhttps://www.blogger.com/profile/12739173686013878533noreply@blogger.comtag:blogger.com,1999:blog-27854051.post-2853775666812085222012-04-08T04:48:03.413+03:002012-04-08T04:48:03.413+03:00And objects __dict__ holds only attributes defined...And objects __dict__ holds only attributes defined withing the object, not in class or base class. See http://codepad.org/PhGMzpVn for example.<br /><br />As said, this is a super simple example. If you need something more complicated I agree you should look elsewhere :)<br />However I find this one is enough for me.Miki Tebekahttps://www.blogger.com/profile/03296782049507092947noreply@blogger.comtag:blogger.com,1999:blog-27854051.post-53962120356005613162012-04-07T19:13:39.615+03:002012-04-07T19:13:39.615+03:00It's interesting to write your own, but there ...It's interesting to write your own, but there are a few gotchas. <br /><br />The attribute you are restoring mat not have been defined on the owning object. It may have been defined on that object's class, or one of the classes' bases. So your __exit__ doesn't always put things back precisely as they were.<br /><br />Highly recommend using Michael Foord's Mock library instead of rolling your own. It fixes many unexpected complications like this.jonathan hartleyhttp://tartley.comnoreply@blogger.comtag:blogger.com,1999:blog-27854051.post-88700552717342106082012-02-23T15:35:24.867+02:002012-02-23T15:35:24.867+02:00Good catch, I forgot to .copy the object original ...Good catch, I forgot to .copy the object original __dict__ (line 28). Fixed now - thanks.Miki Tebekahttps://www.blogger.com/profile/03296782049507092947noreply@blogger.comtag:blogger.com,1999:blog-27854051.post-40303316859111635212012-02-23T11:54:49.556+02:002012-02-23T11:54:49.556+02:00I tried this out, but the object wouldn't be f...I tried this out, but the object wouldn't be fully restored on context exit.<br /><br />This is what worked for me :<br /><br /> def __enter__(self):<br /> self.original = dict(self.obj.__dict__)<br /> self.obj.__dict__.update(self.mocks)<br /> return self<br /><br /> def __exit__(self, typ, val, traceback):<br /> self.obj.__dict__ = self.originalAnonymousnoreply@blogger.com