[Twisted-Python] Help with Simple Trial unit test

Shawn Smiley ssmiley483 at yahoo.com
Wed Jan 30 15:16:10 MST 2008


Thanks a bunch Jean-Paul!!!

That was exactly my problem.

I replaced the reactor.run() line with "return d" and everything works perfectly.

So I guess the lesson here is that if a unit test creates a defer it needs to return that defer for everything to be hooked up properly and execute.


----- Original Message ----
From: Jean-Paul Calderone <exarkun at divmod.com>
To: Twisted general discussion <twisted-python at twistedmatrix.com>
Sent: Wednesday, January 30, 2008 2:01:34 PM
Subject: Re: [Twisted-Python] Help with Simple Trial unit test


On 
Wed, 
30 
Jan 
2008 
13:45:08 
-0800 
(PST), 
Shawn 
Smiley 
<ssmiley483 at yahoo.com> 
wrote:
>Hi 
all,
>
>I 
recently 
started 
learning 
Python 
& 
Twisted 
in 
prep 
for 
a 
big 
project 
at 
work.  
So 
far 
things 
are 
going 
well, 
except 
that 
I 
can't 
quite 
figure 
out 
what 
I'm 
doing 
wrong 
in 
this 
simple 
unit 
test 
I'm 
writing.
>
>One 
of 
the 
features 
of 
the 
project 
I'll 
be 
working 
on 
is 
the 
implementation 
of 
a 
simple 
HTTP 
GET 
Based 
communication 
layer 
between 
legacy 
systems.  
As 
such, 
I 
wanted 
to 
write 
a 
simple 
unit 
test 
that 
uses 
the 
twisted 
client.getPage() 
method 
to 
test 
the 
communication 
process 
(i.e. 
simulates 
a 
legacy 
system 
requesting 
data 
from 
the 
server).
>
>I 
have 
a 
test 
that 
sort 
of 
works.  
However, 
I 
find 
that 
I 
have 
to 
add 
a 
reactor.run() 
command 
in 
the 
unit 
test 
for 
the 
test 
to 
actually 
be 
executed.  
The 
unfortunate 
side 
affect 
of 
this 
is 
that 
you 
then 
have 
to 
ctrl+C 
to 
stop 
the 
reactor 
after 
the 
test 
runs.  
If 
I 
don't 
put 
in 
the 
reactor.run() 
command, 
I 
get 
a 
"REACTOR 
UNCLEAN" 
error 
message 
and 
the 
test 
doesn't 
appear 
to 
run 
(at 
least 
the 
callbacks 
from 
getPage() 
never 
happen).

What 
happens 
if 
you 
take 
the 
Deferred 
created 
in 
the 
test 
method 
and 
return
it, 
instead 
of 
calling 
reactor.run()?

Jean-Paul

_______________________________________________
Twisted-Python 
mailing 
list
Twisted-Python at twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python





      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 





More information about the Twisted-Python mailing list