Connecting multiple test cases in a sort of pipe

  • Thread starter Raghuram Devarakonda
  • Start date
R

Raghuram Devarakonda

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
 
D

Diez B. Roggisch

Raghuram said:
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
 
R

Raghuram Devarakonda

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top