unittest inconsistent

M

Matt Haggard

Can anyone tell me why this test fails?

http://pastebin.com/f20039b17

This is a minimal example of a much more complex thing I'm trying to
do. I'm trying to hijack a function and inspect the args passed to it
by another function.

The reason the 'Tester' object has no attribute 'arg1' is because
"self" still refers to the object made for testA.
 
P

Phlip

Can anyone tell me why this test fails?

http://pastebin.com/f20039b17

This is a minimal example of a much more complex thing I'm trying to
do.  I'm trying to hijack a function and inspect the args passed to it
by another function.

The reason the 'Tester' object has no attribute 'arg1' is because
"self" still refers to the object made for testA.

I hope someone else can spot the low-level reason...

....but why aren't you using http://pypi.python.org/pypi/mock/ ? Look
up its patch_object facility...
 
A

André

Can anyone tell me why this test fails?

http://pastebin.com/f20039b17

This is a minimal example of a much more complex thing I'm trying to
do.  I'm trying to hijack a function and inspect the args passed to it
by another function.

The reason the 'Tester' object has no attribute 'arg1' is because
"self" still refers to the object made for testA.

Quick answer: change faketest.py as follows:

#--------------------------------------------------
# faketest.py
#--------------------------------------------------

#from importme import render
import importme

def run(somearg):
return importme.render(somearg)

=========
A long answer, with explanation, will cost you twice as much ;-)
(but will have to wait)

André
 
P

Peter Otten

André said:
Quick answer: change faketest.py as follows:

#--------------------------------------------------
# faketest.py
#--------------------------------------------------

#from importme import render
import importme

def run(somearg):
return importme.render(somearg)

=========
A long answer, with explanation, will cost you twice as much ;-)
(but will have to wait)

André

Or you figure it out yourself staring at
42

from module import name

binds the object referred to by module.name to the name variable in the
current module. You can think of it as a shortcut for

import module
name = module.name
del module

When you later rebind

import module
module.name = something_else

the reference in the current module isn't magically updated to point to
something_else.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top