Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52166
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <balderman@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.006 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'attribute': 0.07; 'method.': 0.07; 'tries': 0.07; '8bit%:78': 0.09; 'advice?': 0.09; 'below).': 0.09; 'decorator': 0.09; 'expectation': 0.09; 'method,': 0.09; 'url:voidspace': 0.09; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; 'def': 0.12; 'belongs': 0.16; 'client()': 0.16; 'fine.': 0.16; 'message-id:@unknownmsgid': 0.16; 'url:patch': 0.16; 'wrote:': 0.18; 'module': 0.19; 'cc:addr:python.org': 0.22; 'print': 0.22; 'rid': 0.24; 'cc:2**0': 0.24; '(see': 0.26; 'class.': 0.26; 'pass': 0.26; 'header:In- Reply-To:1': 0.27; 'patch': 0.29; 'code': 0.31; "skip:' 10": 0.31; 'class': 0.32; 'url:python': 0.33; '-----': 0.33; 'could': 0.34; 'created': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'unit': 0.37; 'thank': 0.38; 'skip:\xc2 10': 0.60; 'you.': 0.62; 'information': 0.63; 'name': 0.63; 'iphone': 0.65; 'notice:': 0.67; '8bit%:74': 0.68; 'person,': 0.68; 'privileged.': 0.69; 'disclose': 0.74; 'decorate': 0.84; 'mock': 0.84; '2013,': 0.91; '8bit%:70': 0.91; 'medium.': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:from:mime-version:in-reply-to:date:message-id:subject:to :cc:content-type; bh=wFkxpjos0Vf3U1qBevKlFoyjHwz2jWrx2EDH8Z3L4E8=; b=g1LX9bfgXOwjzozk7/2R7KwyoWCqlmYqT6rEwi9ij4y2+RNXJHgsOe7tQ2nXQlmqHF Yus7JPrjjESi9oj+hCSKYhVSCcLqxsaZrIRy8aa/xxm8T0SjS87jgo26+1PhE48RqLSf hvI4ZyOVYHCHsLjnpeLTejiARgcFjDQ8UOW3YKUVYFunN8KTEF4K8usJDMSGf7XTHSQ0 wAIr9z183veHYydsuKFN9yqG1MzsQlW6mI8Z8GwOdaO8aT/Q/oJ3G2kkvpp1E3rvEsLT O2BSRucXmc01RjTd5bWzQfFfwtNBgwH+ST/grV9QBPFskX93NpgQlGs3KioFWNnW45E/ JxSw== |
| X-Received | by 10.68.101.225 with SMTP id fj1mr4155963pbb.8.1375937512735; Wed, 07 Aug 2013 21:51:52 -0700 (PDT) |
| References | <1126236036.30435698.1375898514852.JavaMail.root@sequans.com> |
| From | Avishay Balderman <balderman@gmail.com> |
| Mime-Version | 1.0 (1.0) |
| In-Reply-To | <1126236036.30435698.1375898514852.JavaMail.root@sequans.com> |
| Date | Thu, 8 Aug 2013 07:51:50 +0300 |
| Subject | Re: Mock pathc question |
| To | Jean-Michel Pichavant <jeanmichel@sequans.com> |
| Content-Type | multipart/alternative; boundary=047d7b673288ae0bde04e3686a91 |
| Cc | "python-list@python.org" <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.337.1375937516.1251.python-list@python.org> (permalink) |
| Lines | 158 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1375937516 news.xs4all.nl 15878 [2001:888:2000:d::a6]:60677 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:52166 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Hi
1) I prefer to use start/stop and not the decorator .
2) mock_play is the name of the module where the code belongs
Thanks
Avishay
Sent from my iPhone
On 7 באוג 2013, at 21:01, Jean-Michel Pichavant <jeanmichel@sequans.com>
wrote:
----- Mail original -----
Hi
I would like to mock patch the attribute 'calc' in the 'Client' class
(See code below).
I have 2 unit tests:
1) test1 - that patch an existing instance of 'Client' - it works
fine.
1) test2 - that tries to patch the 'Client' class. My expectation is
that after the patching, every instance of 'Client' will be created
with 'MockClient'. However this is not the case..
Can you please advice?
Thanks
Avishay
One way to do this is to decorate the test2 method,
http://www.voidspace.org.uk/python/mock/patch.html.
This way you get rid of all the start/stop boiler-plate, the scope of your
patch is the scope of the method.
*code not tested*
class TestIt(unittest.TestCase):
def setUp(self):
pass
@mock.patch(Calc, MockCalc)
def test2(self):
client = Client()
# result should be 7
print str(client.add(1,34))
def test3(self):
client = Client()
# result should be 35 again
print str(client.add(1,34))
By the way, what is 'mock_play' in your original post, could be the reason
why you things did go wrong.
JM
-- IMPORTANT NOTICE:
The contents of this email and any attachments are confidential and may
also be privileged. If you are not the intended recipient, please notify
the sender immediately and do not disclose the contents to any other
person, use it for any purpose, or store or copy the information in any
medium. Thank you.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Mock pathc question Avishay Balderman <balderman@gmail.com> - 2013-08-08 07:51 +0300
csiph-web