473,396 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

still not happy with unittest.failUnlessRaises

hi folks,

while I got my own errors kind of sorted out now (I think), unittest
still not behaves like it should.

code:
print 'this is expected to fail. The "Type" column is unique in the DB'
self.failUnlessRaises(IntegrityError, self.failhelper(certs.Subcacert,
self.ca_client_tmpl))

traceback:
File "/usr/lib/python2.2/site-packages/SQLObject/DBConnection.py", line
767, in _queryInsertID c.execute(q)
File "/usr/lib/python2.2/site-packages/sqlite/main.py", line 243, in
execute self.rs = self.con.db.execute(SQL)
IntegrityError: column type is not unique

----------------------------------------------------------------------
Ran 1 test in 56.245s

FAILED (errors=1)

the docu (2.2) says:
failUnlessRaises( exception, callable, ...)
....The test passes if exception is raised, is an error if another
exception is raised, or fails if no exception is raised.

and:
issubclass(sqlite.IntegrityError, Exception)
True

IMO the test should pass. Any ideas what could be wrong here?

thanks
Paul
Jul 18 '05 #1
2 2438
[paul koelle]
while I got my own errors kind of sorted out now (I think), unittest
still not behaves like it should.

code:
print 'this is expected to fail. The "Type" column is unique in the DB'
By "this is expected to fail", do you mean that the test is supposed
to fail, or that the test is supposed to pass by verifying that the
thing it's testing fails? "This" is ambiguous. I'll assume the
latter.
self.failUnlessRaises(IntegrityError, self.failhelper(certs.Subcacert, self.ca_client_tmpl))

What you're actually testing here is that IntegrityError gets raised by

temp()

where

temp = self.failhelper(certs.Subcacert, self.ca_client_tmpl)

is evaluated outside the control of failUnlessRaises.
failUnlessRaises *calls* its second argument. If

self.failhelper(certs.Subcacert, self.ca_client_tmpl)

on its own raises IntegrityError, and that's what you intended to
test, then you need to spell the test

self.failUnlessRaises(IntegrityError, self.failhelper,
certs.Subcacert, self.ca_client_tmpl)

You didn't show enough code so that a reader could guess the answers
to these questions.
...
the docu (2.2) says:
failUnlessRaises( exception, callable, ...)
...The test passes if exception is raised, is an error if another
exception is raised, or fails if no exception is raised.


Yes. Note that the second argument is a callable object, and the
'...' consists of arguments to pass to the callable. So, e.g., the
test

self.failUnlessRaises(ValueError, math.sqrt(-1))

fails, but the test

self.failUnlessRaises(ValueError, math.sqrt, -1)

passes.
Jul 18 '05 #2
Tim Peters wrote:
[paul koelle]
code:
print 'this is expected to fail. The "Type" column is unique in the DB'

By "this is expected to fail", do you mean that the test is supposed
to fail, or that the test is supposed to pass by verifying that the
thing it's testing fails? "This" is ambiguous. I'll assume the
latter.

correct.

[ snipp ] You didn't show enough code so that a reader could guess the answers
to these questions.

My apologies. In fact, it turned out to be simple as:
self.failUnlessRaises(IntegrityError, certs.Subcacert.new,
**self.client_tmpl)

thanks again
Paul
Jul 18 '05 #3

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

Similar topics

1
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...
0
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...
1
by: Thomas Heller | last post by:
I'm trying to integrate some doctest tests with unittest. The tests must be exposed as one or more subclasses of unittest.TestCase, so I'm collecting them with a call to doctest.DocTestSuite(),...
41
by: Roy Smith | last post by:
I've used the standard unittest (pyunit) module on a few projects in the past and have always thought it basicly worked fine but was just a little too complicated for what it did. I'm starting a...
2
by: could ildg | last post by:
I want to know something about unittest these days, and since I'm learning python, I want to touch it through python. But when I found the newest pyunit is even so old, I wonder if it is still...
3
by: David Vincent | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hello I'm hoping to get some insight into a situation that seems odd to me. My Python experience is limited; I've just started using the unittest module....
2
by: Oleg Paraschenko | last post by:
Hello, I decided to re-use functionality of "unittest" module for my purposes. More precisely, I have a list of folders. For each folder, code should enter to the folder, execute a command and...
0
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...
1
by: Olivier Langlois | last post by:
Hi, I have the following statement in my test : self.assertRaises(CDKeyException, ValidationObject.Validate, 1001,'NonExistantKey') and the test fails as if assertRaises was not catching...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...

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.