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.Syst emExit Traceback (most
recent call last)
/Users/chris/<ipython console>
/Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/
unittest.py in __init__(self=< unittest.TestPr ogram object at
0x10ee670>, module='__main_ _', defaultTest=Non e, argv=['/usr/local/
bin/ipython'], testRunner=None , testLoader=<uni ttest.TestLoade r
object at 0x606290>)
757 self.progName = os.path.basenam e(argv[0])
758 self.parseArgs( argv)
--759 self.runTests()
self.runTests = <bound method TestProgram.run Tests of
<unittest.TestP rogram object at 0x10ee670>>
760
761 def usageExit(self, msg=None):
/Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/
unittest.py in runTests(self=< unittest.TestPr ogram object at 0x10ee670>)
795 self.testRunner = TextTestRunner
(verbosity=self .verbosity)
796 result = self.testRunner .run(self.test)
--797 sys.exit(not result.wasSucce ssful())
global sys.exit = <built-in function exit>
result.wasSucce ssful = <bound method
_TextTestResult .wasSuccessful of <unittest._Text TestResult 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(unitte st.TestCase):
def testCoalMiningD isasters(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.s ample(iteration s,
burn=burn, thin=thin, plot=True))
# Run convergence diagnostics
self.sampler.co nvergence()
# Plot autocorrelation
self.sampler.au tocorrelation()
# Goodness of fit
x, n = self.sampler.go odness(iteratio ns/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
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.Syst emExit Traceback (most
recent call last)
/Users/chris/<ipython console>
/Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/
unittest.py in __init__(self=< unittest.TestPr ogram object at
0x10ee670>, module='__main_ _', defaultTest=Non e, argv=['/usr/local/
bin/ipython'], testRunner=None , testLoader=<uni ttest.TestLoade r
object at 0x606290>)
757 self.progName = os.path.basenam e(argv[0])
758 self.parseArgs( argv)
--759 self.runTests()
self.runTests = <bound method TestProgram.run Tests of
<unittest.TestP rogram object at 0x10ee670>>
760
761 def usageExit(self, msg=None):
/Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/
unittest.py in runTests(self=< unittest.TestPr ogram object at 0x10ee670>)
795 self.testRunner = TextTestRunner
(verbosity=self .verbosity)
796 result = self.testRunner .run(self.test)
--797 sys.exit(not result.wasSucce ssful())
global sys.exit = <built-in function exit>
result.wasSucce ssful = <bound method
_TextTestResult .wasSuccessful of <unittest._Text TestResult 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(unitte st.TestCase):
def testCoalMiningD isasters(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.s ample(iteration s,
burn=burn, thin=thin, plot=True))
# Run convergence diagnostics
self.sampler.co nvergence()
# Plot autocorrelation
self.sampler.au tocorrelation()
# Goodness of fit
x, n = self.sampler.go odness(iteratio ns/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
Comment