[Pyunit-interest] test case independence
Brought to you by:
purcell
From: J.D. H. <gt...@ma...> - 2002-04-14 17:18:07
|
I'm having some problems with my unit tests failing on working code (the code I'm testing is rather trivial code that I was using to teach myself pyunit with). It seems to me that for some reason the tests in the test case are stepping on each other, but then this is my first time using pyunit specifically and unit testing in general. Here's the test code: class SeedTestCase(unittest.TestCase): "Test cases for class Seed" def setUp(self): self.seed = db.Seed('name') def tearDown(self): self.seed = None def testSeed(self): """Tests whether Seed.__str__() returns the proper string""" self.assertEqual(self.seed.__str__(), 'name') def testName(self): """Tests whether Seed.name() returns the name string""" self.assertEqual(self.seed.name(), 'name') def testSetValue(self): """Tests whether Seed.setValue() successfully sets or adds a value to Seed""" self.seed.setValue('key', 'foo') self.assertEqual(self.seed.getValue('key'), 'foo') def testAddNewValue(self): """Tests whether Seed.addValue() can add a value to Seed""" self.seed.addValue('key', 'value') self.assertEqual(self.seed.getValue('key'), 'value') def testAddExistingValue(self): """Tests whether Seed.addValue() raises an exception when trying to add with an existing key""" self.seed.addValue('key', 'value') self.assertRaises(db.KeyExistsError, self.seed.addValue, 'key', 'foo') self.assertEquals(self.seed.getValue('key'), 'value') def testGetValueFailure(self): """Tests whether Seed.getValue() raises an exception when it can't find key""" self.assertRaises(db.NoSuchKeyError, self.seed.getValue, 'key') #def testDelValue(self): # """Tests whether Seed.delValue() can remove a key:value def testSuite(): return unittest.makeSuite(SeedTestCase, 'test') I'm invoking the test runner in the python shell using 'runner.run(dbtest.testSuite())' and testGetValueFailure() is failing: ====================================================================== FAIL: Tests whether Seed.getValue() raises an exception when it can't find key ---------------------------------------------------------------------- Traceback (most recent call last): File "C:\Documents and Settings\J.D. Hollis\My Documents\garden\plant\dbtest.py", line 41, in testGetValueFailure self.assertRaises(db.NoSuchKeyError, self.seed.getValue, 'key') File "C:\Python22\lib\unittest.py", line 279, in failUnlessRaises raise self.failureException, excName AssertionError: NoSuchKeyError ---------------------------------------------------------------------- That shouldn't happen (I don't think), assuming we're testing a newly created data structure. Any help is appreciated, either with the design of my unit tests, or with why they're failing. Cheers, J.D. |