[TIP] Supporting multiple fixtures for a test suite

Kumar McMillan kumar.mcmillan at gmail.com
Thu Jan 3 17:56:57 PST 2008


> On Thu, Jan 03, 2008 at 03:26:29PM -0500, Gary Bernhardt wrote:
> -> So finally, the question I have is: how do you guys deal with
> -> overloaded tests like this?

I use the package level setup/teardown feature of nose so that I only
have to create my setup code once.  In nose, if a package looks like
this:

mymodule/__init__.py
mymodule/tests/__init__.py

...then you can add a single setup() method to tests/__init__.py and
it will be called *once* before the entire suite is run.

I use environment variables because it seems like a logical approach
to me.  They are all listed in my test suite's docs, which is how I
remember what the names are.  Specifically, I use this to test web
services.  The tests themselves always think they are connecting to
the host stage.fooservice.  However, they are really connecting to an
in-process stub service unless an environment var explicitly says not
to.  The tests/__init__.py file looks something like:

def setup():
    if os.getenv('USE_REAL_SERVICE','0') != '1':
        wsgi_intercept.add_wsgi_intercept('stage.fooservice', 80,
my_stub_service)

This is abbreviated but you get the idea.

That answered the question of "how do you guys deal with it" but
doesn't really address your choice of trying to switch between
paste.fixture and direct HTTP testing.  However, if you went with an
intercept approach you would still get all the speed benefits from
having an in-process wsgi app.

K



More information about the testing-in-python mailing list