Addition for 1.0/Testing#testing-your-model

1 view
Skip to first unread message

Doug Latornell

unread,
Mar 29, 2008, 12:48:10 PM3/29/08
to TurboGears Docs
I think it should be noted in the Testing Your Model section of
http://docs.turbogears.org/1.0/Testing that testutil.DBTest provides
setUp() and tearDown() methods that create and drop (respectively) the
tables for your model. That means that if you want to define your own
setUp/tearDown for tests in a class that inherits from testutil.DBTest
you either need to handle the creates/drops yourself, or do something
like:

def setUp(self):
testutil.DBTest.setUp(self)
# the rest of your setup code...

and the same sort of thing for tearDown.

You can see what I mean by simply adding do-nothing setUp/tearDown to
a testutil.DBTest test class:

def setUp(self):
pass

def tearDown(self):
pass

Test that previously passed will fail, complaining about non-existent
database tables.

Doug

Christopher Arndt

unread,
Mar 30, 2008, 8:52:22 AM3/30/08
to turboge...@googlegroups.com
Doug Latornell schrieb:

> I think it should be noted in the Testing Your Model section of
> http://docs.turbogears.org/1.0/Testing that testutil.DBTest provides
> setUp() and tearDown() methods that create and drop (respectively) the
> tables for your model.

Does the default implementation support SO and SA or only the former?

> That means that if you want to define your own
> setUp/tearDown for tests in a class that inherits from testutil.DBTest
> you either need to handle the creates/drops yourself, or do something
> like:
>
> def setUp(self):
> testutil.DBTest.setUp(self)
> # the rest of your setup code...

That should probably be 'super(MyTest, self).setUp()', shouldn't it?

Can you file "Documentation" enhancement ticket please?

Extra karma points for providing a diff for the new text :-)


Chris

Doug Latornell

unread,
Mar 31, 2008, 1:32:35 AM3/31/08
to TurboGears Docs
On Mar 30, 5:52 am, Christopher Arndt <chris.ar...@web.de> wrote:
> Doug Latornell schrieb:
>
> > I think it should be noted in the Testing Your Model section of
> >http://docs.turbogears.org/1.0/Testingthat testutil.DBTest provides
> > setUp() and tearDown() methods that create and drop (respectively) the
> > tables for your model.
>
> Does the default implementation support SO and SA or only the former?

Certainly SO, but I'm not sure about SA. I'll try to figure that out
and get back.

>
> > That means that if you want to define your own
> > setUp/tearDown for tests in a class that inherits from testutil.DBTest
> > you either need to handle the creates/drops yourself, or do something
> > like:
>
> > def setUp(self):
> > testutil.DBTest.setUp(self)
> > # the rest of your setup code...
>
> That should probably be 'super(MyTest, self).setUp()', shouldn't it?

Yeah, you're right, that's more correct and idiomatic, though the
other works...

>
> Can you file "Documentation" enhancement ticket please?

Will do.
>
> Extra karma points for providing a diff for the new text :-)

I like karma!! I'll see what I can do.

Doug

Doug Latornell

unread,
Apr 29, 2008, 12:09:31 AM4/29/08
to TurboGears Docs
Finally got some time in on this - sorry for taking so long.

The default implementation supports only SO. The only SA support I
can see in testutil is the sqlalchemy_cleanup() method.

I've created http://trac.turbogears.org/ticket/1814 which includes a
patch that I hope clarifies the setUp/tearDown methods operation, and
explains how to augment them with one's own setUp/tearDown code.

Doug

Christopher Arndt

unread,
Apr 29, 2008, 2:44:55 PM4/29/08
to turboge...@googlegroups.com
Doug Latornell schrieb:


Thanks, I will look at it tomorrow.

Chris

Reply all
Reply to author
Forward
0 new messages