weird unittest result

  • Thread starter Gonçalo Rodrigues
  • Start date
G

Gonçalo Rodrigues

Hi,

I use the unittest module for testing a given module's functionality,
by lumping several test classes and then at the end a simple

if __name__ == "__main__":
unittest.main()

In one of these, I get, at a DOS prompt the following weird result:

C:\Gonçalo\Programming\Python\Code\Library\Connection>c:\python23\python
TestSocketstream.py
.....Exception exceptions.AttributeError: "'Socket' object has no
attribute '_Socket__socket'" in ignored
...
----------------------------------------------------------------------
Ran 6 tests in 0.040s

OK

All tests passing and yet some AttributeError is raised somewhere.
This is even more bizarre because the Socket object does have a
private __socket attribute.

Anyone has an inkling of what might be going on?

With my best regards,
G. Rodrigues
 
J

John J. Lee

Gonçalo Rodrigues said:
....Exception exceptions.AttributeError: "'Socket' object has no
attribute '_Socket__socket'" in ignored [...]
All tests passing and yet some AttributeError is raised somewhere.

The exception message seems to have been damaged in the cut-n-paste.
Could it be that an exception was thrown in a __del__ method?

Plenty of threads in Google Groups about this, if you want to know
more (exception ignored group:comp.lang.python).

This is even more bizarre because the Socket object does have a
private __socket attribute.

Not if it has already been deleted, I guess.


John
 
P

Peter Hansen

Gonçalo Rodrigues said:
I use the unittest module for testing a given module's functionality,
by lumping several test classes and then at the end a simple

if __name__ == "__main__":
unittest.main()

In one of these, I get, at a DOS prompt the following weird result:

C:\Gonçalo\Programming\Python\Code\Library\Connection>c:\python23\python
TestSocketstream.py
....Exception exceptions.AttributeError: "'Socket' object has no
attribute '_Socket__socket'" in ignored
..
----------------------------------------------------------------------
Ran 6 tests in 0.040s

All tests passing and yet some AttributeError is raised somewhere.
This is even more bizarre because the Socket object does have a
private __socket attribute.

Anyone has an inkling of what might be going on?

The tests appear to be passing because something is catching the
exception and ignoring it. The above exception is not a normal
exception message, so I think some code is printing that message
in an exception handler somewhere.

As for your comment about "even more bizarre", I think the whole
point of the message is that Socket doesn't have a __socket
attribute, but clearly some code somewhere thinks it does and is
attempting to access it.

Would it help if I pointed out that the standard Python socket
object is "socket" and not "Socket"? Maybe you're getting confused
about what code is really being executed.

Sorry I can't help more.

-Peter
 
G

Gonçalo Rodrigues

Gonçalo Rodrigues said:
....Exception exceptions.AttributeError: "'Socket' object has no
attribute '_Socket__socket'" in ignored [...]
All tests passing and yet some AttributeError is raised somewhere.

The exception message seems to have been damaged in the cut-n-paste.
Could it be that an exception was thrown in a __del__ method?

Thanks! I've been able to track the problem and it's precisely in a
subtle interplay between a test testing that a certain exception is
raised (which implies that the __init__ method is not completed) and
the __del__ method.

Simplest solution: delete __del__, it's not needed anywhere.

With my best regards,
G. Rodrigues
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top