weird unittest result

Discussion in 'Python' started by Gonçalo Rodrigues, Oct 1, 2003.

  1. 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
    Gonçalo Rodrigues, Oct 1, 2003
    #1
    1. Advertising

  2. Gonçalo Rodrigues

    John J. Lee Guest

    Gonçalo Rodrigues <> writes:
    [...]
    > ....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
    John J. Lee, Oct 1, 2003
    #2
    1. Advertising

  3. Gonçalo Rodrigues

    Peter Hansen Guest

    "Gonçalo Rodrigues" wrote:
    >
    > 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
    Peter Hansen, Oct 1, 2003
    #3
  4. On 01 Oct 2003 18:29:21 +0100, (John J. Lee) wrote:

    >Gonçalo Rodrigues <> writes:
    >[...]
    >> ....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
    Gonçalo Rodrigues, Oct 2, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul  Moore
    Replies:
    1
    Views:
    374
    Paul Moore
    Oct 14, 2008
  2. J.Ram
    Replies:
    7
    Views:
    636
  3. Pavel
    Replies:
    7
    Views:
    503
    Pavel
    Sep 19, 2010
  4. Lakshmi Sreekanth

    i = 10; result = ++i - --i; How result become ZERO

    Lakshmi Sreekanth, Sep 21, 2010, in forum: C Programming
    Replies:
    52
    Views:
    1,130
    Nick Keighley
    Sep 23, 2010
  5. Michael Tan
    Replies:
    32
    Views:
    907
    Ara.T.Howard
    Jul 21, 2005
Loading...

Share This Page