Connecting multiple test cases in a sort of pipe

Diez B. Roggisch deets at
Thu Jul 30 08:43:27 CEST 2009

Raghuram Devarakonda schrieb:
> Hi,
> I have three functions - create(), list(), and delete(). create()
> creates a new name in the file system hierarchy while list() displays
> all such created names and delete() removes them. I would like to
> write test cases for each of these functions, say, test_create() ,
> test_list(), and test_delete() using the unittest module. It easily
> follows that test_list() and test_delete() will need to know the exact
> name that was created in test_create() in order to properly validate
> list() and delete(). One option is for test_create() to always use a
> hard coded name but unfortunately this is not feasible.
> Another way would be for test_create() to pass the new name down to
> the next test case test_list() which would do the same and pass the
> name down to test_delete(). In other words, the requirement is to
> connect all three test cases in a kind of pipe. This facility is
> obviously not currently present in the unittest module and nor does it
> seem to be available in other frameworks (such as py.test and nose, I
> only skimmed the feature list).
> I am thinking of implementing this feature on top of unittest.TestCase
> and would like to know what others think of the idea. Is there a
> framework that has similar feature? Or perhaps, given my requirement
> as stated above, is there some alternate way of implementing it? I
> greatly appreciate any feed back.

Write a TestCase-subclass that simply works like this:

class FileTests(TestCase):

    def test_create(self):
        self.created_file = create()
        assert something

    def test_list(self):

Passing state around is one of the reasons objects have been invented :) 
And nobody ever said that you can't invoke a test-method from somewhere 


More information about the Python-list mailing list