fundamental issue with unittest
Chris Fonnesbeck
fonnesbeck at gmail.com
Tue Aug 8 10:43:02 EDT 2006
I have added a unit test to some of my code, following closely the examples
in the python docs and python in a nutshell. However, when I try calling
unittest.main(), I get the following:
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
---------------------------------------------------------------------------
exceptions.SystemExit Traceback (most recent
call last)
/Users/chris/<ipython console>
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/PyMC/MCMC.py
in runtest()
2916
2917
2918 def runtest():
2919 # Run unit tests
-> 2920 unittest.main()
global unittest.main = <class 'unittest.TestProgram'>
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/unittest.py
in __init__(self=<unittest.TestProgram object at 0x10e1970>,
module='__main__', defaultTest=None, argv=['/usr/local/bin/ipython'],
testRunner=None, testLoader=<unittest.TestLoader object at 0x5ff870>)
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 0x10e1970>>
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 0x10e1970>)
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=0 errors=0 failures=0>>
798
799 main = TestProgram
SystemExit: False
Type exit or quit to exit IPython (%Exit or %Quit do so unconditionally).
My unit testing code is here:
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
self.failIf(any(self.sampler.goodness(iterations/10)['overall'] <
0.05))
def runtest():
# Run unit tests
unittest.main()
I appear to be subclassing appropriately, and the only method begins with
"test", so I do not see the problem. Can anyone help me out?
Thanks,
C.
--
Chris Fonnesbeck + Atlanta, GA + http://trichech.us
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060808/4acb3fbc/attachment.html>
More information about the Python-list
mailing list