unittest, order of test execution

mk mrkafk at gmail.com
Mon Jan 26 03:14:51 EST 2009


Hello everyone,

I've got 2 functions to test, extrfromfile which returns a list of 
dictionaries, and extrvalues that extracts values from that list.

Now I can test them both in one test case, like this:

     def test_extrfromfile(self):
         valist = ma.extrfromfile('loadavg_unittest.txt')
         valist_ut = [ {'day': '08-11-19', 'time': '12:41', 'val': 0.11},
                       {'day': '08-11-19', 'time': '12:42', 'val': 0.08},
                       {'day': '08-11-19', 'time': '12:43', 'val': 0.57},
                       {'day': '08-11-19', 'time': '12:44', 'val': 0.21},
                       {'day': '08-11-19', 'time': '12:45', 'val': 0.08},
                       {'day': '08-11-19', 'time': '12:46', 'val': 0.66},
                       {'day': '08-11-19', 'time': '12:47', 'val': 0.32},
                       {'day': '08-11-19', 'time': '12:48', 'val': 0.12},
                       {'day': '08-11-19', 'time': '12:49', 'val': 0.47},
                       {'day': '08-11-19', 'time': '12:50', 'val': 0.17}]
         self.assertEqual(valist, valist_ut)

         vlextr_ut = [0.11, 0.08, 0.57, 0.21, 0.08, 0.66, 0.32, 0.12, 
0.47, 0.17]
         vlextr = ma.extrvalues(valist)
         self.assertEqual(len(vlextr_ut), len(vlextr))
         for (idx, elem) in enumerate(vlextr_ut):
             self.assertAlmostEqual(elem, vlextr[idx])


But I was wondering, *should* this test be separated into two unit 
tests, one for each function? On the face of it, it looks that's how it 
should be done.

This, however, raises the question: what's the order of test execution 
in the unittest? And how to pass values between unit tests? Should I 
modify 'self' in unit test?

Regards,
mk




More information about the Python-list mailing list