Connecting multiple test cases in a sort of pipe

Discussion in 'Python' started by Raghuram Devarakonda, Jul 30, 2009.

  1. 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.

    Thanks,
    Raghu
    Raghuram Devarakonda, Jul 30, 2009
    #1
    1. Advertising

  2. 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):
    self.test_create()
    delete(self.created_file)


    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
    else.

    Diez
    Diez B. Roggisch, Jul 30, 2009
    #2
    1. Advertising

  3. On Jul 30, 2:43 am, "Diez B. Roggisch" <> wrote:
    > 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):
    > self.test_create()
    > delete(self.created_file)
    >
    > 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
    > else.


    Just to be clear, are you suggesting that these tests be run by a
    custom runnner rather than by the default runner from unittest?

    Thanks,
    Raghu
    Raghuram Devarakonda, Jul 30, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Georg Schmid

    SetUp functions for multiple test cases

    Georg Schmid, Jan 20, 2009, in forum: Python
    Replies:
    4
    Views:
    557
    brooklineTom
    Jan 20, 2009
  2. Navin
    Replies:
    1
    Views:
    673
    Ken Schaefer
    Sep 9, 2003
  3. Sam Kong
    Replies:
    10
    Views:
    312
    Sam Kong
    Sep 20, 2006
  4. David Mitchell
    Replies:
    10
    Views:
    244
  5. Replies:
    11
    Views:
    191
    Uri Guttman
    Jun 26, 2007
Loading...

Share This Page