unittest - what is the best way to reuse test data?

Mike 42flicks at gmail.com
Wed Jun 3 05:21:10 EDT 2009


Hello,

I'm writing an application that needs to fetch a json file from a webserver.
I'm writing the tests and have a question:

if I have the following methods:

def test_headers(self):
    headers = libary.get_data(data)
    check header status

def test_get_info
    info = libary.get_info(libary.get_data(data))

This way I call the url twice, even though I have the data available from
the first test.

my application would just variables such as:
  h = libary.get_data(data)
  i = libary.get_info(h)

so only one call.

What is the best way to set up tests to resuse the data more? I'm new to
using the testing framework so I'm not sure on best practises and such.

Is introducing persistance by using sql lite the best way?  I should be able
to just reuse data within the object. Or is my design wrong?

Any tips or suggestions would be appreciated!

- Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090603/67158929/attachment.html>


More information about the Python-list mailing list