Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87221
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.016 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'yet.': 0.04; 'executed': 0.09; 'function,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'worked,': 0.09; '15,000': 0.16; '8bit%:32': 0.16; 'declared': 0.16; 'defined.': 0.16; 'finney': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'library': 0.18; 'looked': 0.18; 'module': 0.19; 'examples': 0.20; 'header:User-Agent:1': 0.23; 'test.': 0.24; 'daniel': 0.26; 'header:X-Complaints-To:1': 0.27; 'patch': 0.29; 'points': 0.29; 'arts': 0.31; 'writes:': 0.31; 'class': 0.32; 'this.': 0.32; 'another': 0.32; 'url:python': 0.33; 'skip:d 20': 0.34; 'basic': 0.35; 'but': 0.35; 'there': 0.35; 'object,': 0.36; 'url:org': 0.36; 'changing': 0.37; 'two': 0.37; 'ben': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'ensure': 0.60; 'up,': 0.60; 'url:3': 0.61; 'name': 0.63; 'skip:\xe2 10': 0.65; 'covers': 0.68; 'exhibition': 0.68; 'article,': 0.84; 'hunting!': 0.84; 'mock': 0.84; 'object:': 0.84; 'received:125': 0.84; 'soviet': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Ben Finney <ben+python@benfinney.id.au> |
| Subject | Re: Mock return_value |
| Date | Tue, 10 Mar 2015 06:10:05 +1100 |
| References | <e32b0311-3b7b-4f7b-8f3b-212adae7f776@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | jigong.madmonks.org |
| X-Public-Key-ID | 0xAC128405 |
| X-Public-Key-Fingerprint | 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 |
| X-Public-Key-URL | http://www.benfinney.id.au/contact/bfinney-pubkey.asc |
| X-Post-From | Ben Finney <bignose+hates-spam@benfinney.id.au> |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
| Cancel-Lock | sha1:4OoSju3MaXF61tMbXbMcF2uphOE= |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.19 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.224.1425928229.21433.python-list@python.org> (permalink) |
| Lines | 35 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1425928229 news.xs4all.nl 2887 [2001:888:2000:d::a6]:50045 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:87221 |
Show key headers only | View raw
Daniel <daniel.watrous@gmail.com> writes:
> I have a dao.py module with a dao class declared and I want to use
> mock to set a return value for a dao function,
> dao.execute_ldap_search().
You have found a change which worked, but you might not have understood
why yet.
The documentation for the ‘unittest.mock’ library covers the wrinkles of
where to patch an object:
26.4.3.8. Where to patch
patch() works by (temporarily) changing the object that a name
points to with another one. There can be many names pointing to any
individual object, so for patching to work you must ensure that you
patch the name used by the system under test.
The basic principle is that you patch where an object is looked up,
which is not necessarily the same place as where it is defined. A
couple of examples will help to clarify this.
[…]
<URL:https://docs.python.org/3/library/unittest.mock.html#where-to-patch>
Good hunting!
--
\ “There will be a Moscow Exhibition of the Arts by 15,000 Soviet |
`\ Republic painters and sculptors. These were executed over the |
_o__) past two years.” —newspaper article, Soviet Weekly |
Ben Finney
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Mock return_value Daniel <daniel.watrous@gmail.com> - 2015-03-09 08:27 -0700 Re: Mock return_value Daniel <daniel.watrous@gmail.com> - 2015-03-09 08:34 -0700 Re: Mock return_value Ben Finney <ben+python@benfinney.id.au> - 2015-03-10 06:10 +1100 Re: Mock return_value Daniel <daniel.watrous@gmail.com> - 2015-03-09 13:10 -0700
csiph-web