Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52183 > unrolled thread
| Started by | Jean-Michel Pichavant <jeanmichel@sequans.com> |
|---|---|
| First post | 2013-08-08 12:04 +0200 |
| Last post | 2013-08-08 09:15 -0700 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
Re: Mock pathc question Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-08-08 12:04 +0200
Re: Mock pathc question balderman@gmail.com - 2013-08-08 09:15 -0700
| From | Jean-Michel Pichavant <jeanmichel@sequans.com> |
|---|---|
| Date | 2013-08-08 12:04 +0200 |
| Subject | Re: Mock pathc question |
| Message-ID | <mailman.344.1375956285.1251.python-list@python.org> |
----- Mail original -----
> 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
You should not neeed to refer to the Calc class using mock_play since it is defined in the very same file (module).
Possibly mock_play.Calc and Calc are 2 different classes, hence you're not patching the good one.
Note how you patch "mock_play.Calc" and then instanciate using "self.calc = Calc()"
right before
my_mock = mock.patch('mock_play.Calc',create=True, new=MockCalc)
add
print mock_play.Calc
print Calc
and verify that they are both the very same object.
Cheers,
JM
PS : Please do not top post in this list
-- 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.
[toc] | [next] | [standalone]
| From | balderman@gmail.com |
|---|---|
| Date | 2013-08-08 09:15 -0700 |
| Message-ID | <aad7d032-5a08-4bb7-a3c4-93555afec0df@googlegroups.com> |
| In reply to | #52183 |
On Thursday, August 8, 2013 12:04:38 PM UTC+2, Jean-Michel Pichavant wrote:
> ----- Mail original -----
>
> > 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
>
>
> You should not neeed to refer to the Calc class using mock_play since it is defined in the very same file (module).
> Possibly mock_play.Calc and Calc are 2 different classes, hence you're not patching the good one.
>
> Note how you patch "mock_play.Calc" and then instanciate using "self.calc = Calc()"
>
> right before
> my_mock = mock.patch('mock_play.Calc',create=True, new=MockCalc)
>
> add
> print mock_play.Calc
> print Calc
>
>
> and verify that they are both the very same object.
>
> Cheers,
>
> JM
>
>
> PS : Please do not top post in this list
>
>
> -- 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.
Hi
Here is a working solution: http://stackoverflow.com/questions/18121084/mock-patch-does-not-work-properly
thanks
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web