473,387 Members | 1,597 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,387 software developers and data experts.

unittest issues

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:
NameError: global name 'IntegrityError' is not defined.


Do I really need to tell unittest about each and every possible
Exception it might catch. Whats going on here?

python 2.2.3 on linux 2.6.7

thanks
Paul
Jul 18 '05 #1
1 1949
paul koelle <pa**@subsignal.org> wrote:
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:
>>NameError: global name 'IntegrityError' is not defined.


Do I really need to tell unittest about each and every possible
Exception it might catch. Whats going on here?


You need to define any name you use before you use it, quite apart from
unittest. You can't use a name that just isn't defined in that scope,
period: whether you're unit testing or doing anything else, you can't.

Once you have fixed this you'll find another problem: you need to pass
failUnlessRaises the callable and arguments separately, so it can
perform the call within a try clause. What you're doing here is calling
the myObject.new method yourself, so it presumably raises well before
any kind of control is passed to the failUnlessRaises method -- no good.
I'm not sure you can pass an arbitrary set of keywords that way (at the
very least some keyword might happen to conflict with ones used in
unittest itself), so I suggest this approach:

def localfun(): return myObject.new(**stuff)
self.failUnlessRaises(Exception, localfun)

note that here I'm passing the function object itself, NOT the result of
calling it -- there IS quite a difference!
Alex
Jul 18 '05 #2

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

Similar topics

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...
18
by: Scott David Daniels | last post by:
There has been a bit of discussion about a way of providing test cases in a test suite that _should_ work but don't. One of the rules has been the test suite should be runnable and silent at every...
24
by: john_sips_tea | last post by:
For writing testcode, it looks like there's three ways that it's typically done: (1). using the doctest module, (2). using the unittest module (i.e. "pyunit"), or else (3). just putting an...
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...
2
by: Collin Winter | last post by:
While working on a test suite for unittest these past few weeks, I've run across some behaviours that, while not obviously wrong, don't strike me as quite right, either. Submitted for your...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.