[TIP] alphabetical order in testing
holger at merlinux.eu
Wed Jan 20 02:42:13 PST 2010
On Tue, Jan 19, 2010 at 15:35 -0500, Olemis Lang wrote:
> On Tue, Jan 19, 2010 at 3:26 PM, Alfredo Deza <alfredodeza at gmail.com> wrote:
> > Hi
> > I am aware that test methods are executed in alphabetical order.
> > What would be the ideal/preferable way of dealing with methods that depend
> > in the order they are being executed?
> > Given that:
> >> class TestFiles(unittest.TestCase):
> >> def test_second_file(self):
> >> """I depend on z_file"""
> >> def test_z_file(self):
> >> """I should run before second_file"""
> > Would it be OK to alter the naming in the methods to make sure they are run
> > in the order I need to? Even if the naming gets really weird like:
> Very bad practice ! Dependencies between test cases can lead to
> fragile tests . TCs should be as isolated as possible
Some way of telling a test runner to consider tests in a certain
order makes sense to me, though.
In fact, I had user requests and own thoughts to allow declaring dependencies -
such that if a test fails subsequent ones would not be run anymore. py.test
runs tests in the order in which they appear in the file and i am considering
marking a test case/class as being "incremental", i.e. skip/fail tests after
the first tests fails.
More information about the testing-in-python