Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > unit testing failure makes no sense

Reply
Thread Tools

unit testing failure makes no sense

 
 
listservs@mac.com
Guest
Posts: n/a
 
      08-30-2006
I have some unit testing code in one of my modules that appears to
run without an error, but the unit test fails anyhow. Have a look at
the output below -- the TestResult seems to have no errors and no
failures, yet I get a system exit.

------------------------------------------------------------------------
---
exceptions.SystemExit Traceback (most
recent call last)

/Users/chris/<ipython console>

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
unittest.py in __init__(self=<unittest.TestProgram object at
0x10ee670>, module='__main__', defaultTest=None, argv=['/usr/local/
bin/ipython'], testRunner=None, testLoader=<unittest.TestLoader
object at 0x606290>)
757 self.progName = os.path.basename(argv[0])
758 self.parseArgs(argv)
--> 759 self.runTests()
self.runTests = <bound method TestProgram.runTests of
<unittest.TestProgram object at 0x10ee670>>
760
761 def usageExit(self, msg=None):

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
unittest.py in runTests(self=<unittest.TestProgram object at 0x10ee670>)
795 self.testRunner = TextTestRunner
(verbosity=self.verbosity)
796 result = self.testRunner.run(self.test)
--> 797 sys.exit(not result.wasSuccessful())
global sys.exit = <built-in function exit>
result.wasSuccessful = <bound method
_TextTestResult.wasSuccessful of <unittest._TextTestResult run=3
errors=0 failures=0>>
798
799 main = TestProgram

SystemExit: False
Type exit or quit to exit IPython (%Exit or %Quit do so
unconditionally).

Any ideas what is going wrong here? Here is my testing code:

class MCMCTest(unittest.TestCase):

def testCoalMiningDisasters(self):
"""Run coal mining disasters example sampler"""

print 'Running coal mining disasters test case ...'

# Create an instance of the sampler
self.sampler = DisasterSampler()

# Specify the nimber of iterations to execute
iterations = 10000
thin = 2
burn = 5000
chains = 2

# Run MCMC simulation
for i in range(chains):

self.failUnless(self.sampler.sample(iterations,
burn=burn, thin=thin, plot=True))

# Run convergence diagnostics
self.sampler.convergence()

# Plot autocorrelation
self.sampler.autocorrelation()

# Goodness of fit
x, n = self.sampler.goodness(iterations/10)['overall']
self.failIf(x/n < 0.05 or x/n > 0.95)


--
Christopher Fonnesbeck
+ Atlanta, GA
+ fonnesbeck at mac.com
+ Contact me on AOL IM using email address


 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      08-30-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> I have some unit testing code in one of my modules that appears to
> run without an error, but the unit test fails anyhow. Have a look at
> the output below -- the TestResult seems to have no errors and no
> failures, yet I get a system exit.


sys.exit(0) is just a normal way to exit a program, and it is implemented as
'raise SystemExit'. You seem to be running your test from within ipython
which probably catches SystemExit exceptions to prevent you from losing
state. Try running your test from the shell and all should be OK.

Peter
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unit-profiling, similar to unit-testing Ulrich Eckhardt Python 6 11-18-2011 02:00 AM
Test::Unit - Ruby Unit Testing Framework Questions Bill Mosteller Ruby 0 10-22-2009 02:02 PM
Do u think this makes sense?? Developer.Man4@gmail.com ASP .Net 3 12-12-2006 02:41 PM
Sending number - it makes no sense! logiclips@yahoo.com Java 11 09-26-2006 05:49 PM
when GOTO makes sense. Debashish Chakravarty C Programming 45 12-09-2003 07:12 PM



Advertisments