Re: unittest, order of test execution
On Jan 27, 11:33 am, Yinon Ehrlich wrote: > > 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? > > It's OK to run some tests in the same function. > When one of the asserts fails, following the traceback will lead you > straight to your problem. > > The order of test execution is done by default by sorting the test > functions alphabetically. > You may disable the sort by setting self.sortTestMethodsUsing to None. see: http://docs.python.org/library/unittest.html#unittest.TestLoader.sortTestMethodsUsing > The simplest way to pass values between tests is to use the class it > (self). > > Yinon -- http://mail.python.org/mailman/listinfo/python-list
Re: unittest, order of test execution
> 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? It's OK to run some tests in the same function. When one of the asserts fails, following the traceback will lead you straight to your problem. The order of test execution is done by default by sorting the test functions alphabetically. You may disable the sort by setting self.sortTestMethodsUsing to None. The simplest way to pass values between tests is to use the class it (self). Yinon -- http://mail.python.org/mailman/listinfo/python-list
unittest, order of test execution
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 -- http://mail.python.org/mailman/listinfo/python-list