473,586 Members | 2,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

weird unittest result

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\Prog ramming\Python\ Code\Library\Co nnection>c:\pyt hon23\python
TestSocketstrea m.py
.....Exception exceptions.Attr ibuteError: "'Socket' object has no
attribute '_Socket__socke t'" 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
Jul 18 '05 #1
3 1909
Gonçalo Rodrigues <op*****@mail.t elepac.pt> writes:
[...]
....Exception exceptions.Attr ibuteError: "'Socket' object has no
attribute '_Socket__socke t'" 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
Jul 18 '05 #2
"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\Prog ramming\Python\ Code\Library\Co nnection>c:\pyt hon23\python
TestSocketstrea m.py
....Exception exceptions.Attr ibuteError: "'Socket' object has no
attribute '_Socket__socke t'" 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
Jul 18 '05 #3
On 01 Oct 2003 18:29:21 +0100, jj*@pobox.com (John J. Lee) wrote:
Gonçalo Rodrigues <op*****@mail.t elepac.pt> writes:
[...]
....Exception exceptions.Attr ibuteError: "'Socket' object has no
attribute '_Socket__socke t'" 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
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2572
by: Paul Moore | last post by:
One of the things I really dislike about Unittest (compared, say, to a number of adhoc testing tricks I've used in the past, and to Perl's "standard" testing framework) is that the testcase-as-a-class model tends to imply a relatively high granularity in testing. A good example of this comes from "Dive Into Python"...
1
1961
by: paul koelle | last post by:
Hi, I try to use the "failUnlessRaises()" method from unittest.TestCase as follows: >>self.failUnlessRaises(IntegrityError, myObject.new(**stuff)) where IntegrityError is an Exception somewhere deep inside pysqlite. Running it spits out:
8
1821
by: Remy Blank | last post by:
Hello unittest users, In a project I am working on, I have a series of tests that have to be run as root, and others as a normal user. One solution is to separate the tests into two different files, and run the right one. I don't like this too much, as I prefer to group tests by "function". Another solution is to build the test suite...
0
2035
by: Remy Blank | last post by:
Ok, here we go. I added the possibility for tests using the unittest.py framework to be skipped. Basically, I added two methods to TestCase: TestCase.skip(msg): skips unconditionally TestCase.skipIf(expr, msg): skips if expr is true These can be called either in setUp() or in the test methods. I also added reporting of skipped tests to...
1
2710
by: James Jeffers | last post by:
I couldn't find any resource that addresses output from the unittest package in python 2.4.x. I can't beleive that there isn't an output formatter/test runner for the unittest package.. surely some needed this before. Is there a working group or package maintainer for these kinds of features? Thanks in advance, James
5
3566
by: paul kölle | last post by:
hi all, I noticed that setUp() and tearDown() is run before and after *earch* test* method in my TestCase subclasses. I'd like to run them *once* for each TestCase subclass. How do I do that. thanks paul
4
7528
by: Helge Stenstroem | last post by:
Say I have a function def f(filename): result = openFileAndProcessContents(filename) return result Can that function be unit tested without having a real file as input? Something along the lines of import unittest
0
2303
by: Chris Fonnesbeck | last post by:
I have built the following unit test, observing the examples laid out in the python docs: class testMCMC(unittest.TestCase): def setUp(self): # Create an instance of the sampler self.sampler = DisasterSampler()
0
984
by: =?ISO-8859-1?Q?Israel_Fern=E1ndez_Cabrera?= | last post by:
Hi I'm writing some code that automatically execute some registered unit test in a way to automate the process. A sample code follows to illustrate what I'm doing: <code requires="save as import_tests.py"> class PruebasDePrueba(unittest.TestCase): def testUnTest(self): a = 2 b = 1
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.