[py-dev] unit testing error: inconsistenty failed then succeeded

holger krekel hpk at trillke.net
Sun Feb 20 18:54:21 CET 2005


On Sun, Feb 20, 2005 at 18:24 +0100, Felix Schwarz wrote:
> I want to start using pydev for my smaller projects but I get an error
> that I do not understand. What should "inconsistenty failed then
> succeeded" tell me?

py.test tries to re-interpret failing expressions or statements. 
Originally we did it only for assert statements so that you can
see the exact values that evaluted to false.  We extended this 
to basically all kinds of errors but this is a bit fragile 
and can lead to the "failed then succeeded" problem: the expression 
failed originally but when we looked at it again (with our
mini-interpreter) it didn't fail anymore. Now on to your
special case: 

> I'm not a native speaker but this sounds strange to me. But beside my
> problems understanding the error message I don't know why the unit
> test failes at all.
> 
> >     def test_isLoginAttempt_no(self):
> >             userdata = {'username' : 'foo at bar.test', 'password' : 'foobar'}
> > E           login = login.Login(userdata)
> > ~           (inconsistenty failed then succeeded     )
> > [C:\Programme\Apache Group\Apache2\vhosts\junkkiller\cgi-bin\Fehler\test_login.p
> > y:12]
> > [modulepath: TestLogin.test_isLoginAttempt_no]
> 
> Minimal testcases attached.

Thanks.  If you run your test with "--nomagic" (always a good idea if 
you suspect that the test tool has problems) then you should see  

    UnboundLocalError: local variable 'login' referenced before assignment

which means: You import "login" globally but also use it as a
local name and in Python that means it's a local variable only.
Of course, then "login.Login" fails because 'login' has not been 
initialized yet as a local variable.   

However, your problem points to a limitation of our mini-interpreter
in that it probably isn't careful enough with respect to locals/globals
and compilation to prevent this kind of problem ... 

cheers, 

    holger



More information about the Pytest-dev mailing list