[TIP] Testing the Fixture?

iain duncan iainduncan at telus.net
Wed Nov 21 17:18:02 PST 2007


On Wed, 2007-21-11 at 16:41 -0800, Titus Brown wrote:
> -> Could you manually throw an exception that aborts all the remaining
> -> tests? Would there a point to that?
> -> 
> -> # module setup
> -> setup():
> ->   try:
> ->     assert some stuff, 'fixture failed, bailing out'
> ->   catch:
> ->     raise KillerException
> 
> I think someone else answered with the magic bit of code that does this!
> 
> I, however, would argue that this is a bad idea: tests should fail or
> they should succeed.  Having code that relies on local code trickiness
> to ignore or halt successive tests seems like a fantastic way to lose
> test code.

Ok, I'll take your advice on that then. However, I'm getting a hang from
nose when I make it fail in the module setup. I get the output that it
failed on 0 tests, but then nose won't exit. Any idea what the below
should be instead?

Thanks
iain
module level setup below:

# use module level setup/teardown to start/stop server
# by starting the server anew, we clear all session vars
def setup():
    print "module level setup()"
    # fire up the server
    cherrypy.root = Root()
    cherrypy.config.update( test_config )
    cherrypy.server.start( initOnly=True )
    # wipe and recreate the tables
    metadata.drop_all()
    metadata.create_all()
    print "set up putting in starting db content"
    sql_setup = os.system('mysql -uweb -ppasswd -Dtdtg_db_test <
eatlocal_productss.sql')
    assert not sql_setup, 'Setup Error loading in starting sql file'
    assert Product.count() == 15, 'Wrong number of starting products'
    # start off on main url 
    go("http://localhost:9080")






More information about the testing-in-python mailing list