Controller test fixture on module/package level

33 views
Skip to first unread message

Moritz Schlarb

unread,
Sep 25, 2012, 2:39:55 PM9/25/12
to TurboGears
Hi Group!

I already asked this in the IRC channel, but while asking, the question
seemed to better fit to the mailing list:

Thanks to nose, I have written a test generator that takes a (very)
nested data structure and yields test cases from it.
The code is here:
https://github.com/moschlar/SAUCE/blob/develop/sauce/tests/functional/test_site.py
Its purpose is at first for me to check if all types of pages at least
get served without exceptions (regardless of *what* gets rendered in
this case) and to check if authz works correctly for all the pages by
specifying valid HTTP responses.

It works quite well, except for the fact that its slow as hell!
I suspect that it could be much fast, if the test fixture wouldn't have
to be executed for each of these simple HTTP requests. I think I can
safely assume that this won't have negative side effects in this case so
I would like to take the application setUp and tearDown from
sauce.tests.TestController and put them on the module level in the
test_site module.

A first try was unsuccessfull since I couldn't figure out how to get an
app instance initialized that I could use there.

My first try was to simply take the fixture methods and put them on
module level in test_site.py, but that failed with
ResourceClosedError: The transaction is closed
in the setup-app part of the setUp method.

Maybe anyone has a recipe for that or a running example that could
inspire me! :D

Thanks a lot,
Moritz

Michael Pedersen

unread,
Sep 27, 2012, 1:46:02 AM9/27/12
to turbo...@googlegroups.com
Hi there, Moritz. I like the idea of this project *quite* a lot. I
don't have much by way of useful reply right now, but that's because I
haven't ever broken out the test cases to deal with the issues you're
dealing with. The closest I can get is to point out that a simple
quickstart has a minimal testing application (look under
myproject.tests to see it and trace it out). Since, by default, it
uses the sqlite :memory: database, it would probably be most helpful
in getting a speed up for you.

I hope it's at least a starting point for improvement, anyway.
> --
> You received this message because you are subscribed to the Google Groups "TurboGears" group.
> To post to this group, send email to turbo...@googlegroups.com.
> To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.
>



--
Michael J. Pedersen
My Online Resume: http://www.icelus.org/ -- Google+ http://plus.ly/pedersen
Google Talk: m.ped...@icelus.org -- Twitter: pedersentg

Moritz Schlarb

unread,
Sep 27, 2012, 5:28:49 PM9/27/12
to turbo...@googlegroups.com
Hi Michael, and thanks for your effort!

Well, I am in fact already using the test suite derived from quickstart!

My problem is, that this approach will in fact run setup-app (from the test fixture setUp() method) for each (of the ~200 simple app.get()) test cases, which slows the whole thing done, even with the sqlite://:memory: database...

Nose features setUpModule() and setUpPackage() methods which would only run once for all test cases in the module.
The problem is that I couldn't get it to work properly using an persistent app attribute which is set in TestController.

I think I might create an app that demonstrates it... I'll push it somewhere and post here, maybe that helps ;)

Moritz Schlarb

unread,
Sep 27, 2012, 6:06:03 PM9/27/12
to turbo...@googlegroups.com
Oh well... Nevermind!
I engineered it in a fresh quickstart and apparently it's as simple as in this gist: https://gist.github.com/3796718

I might have been missing the global statement before... :-/

Thank you anyway and maybe it's of some use for anyone else! ;)
Reply all
Reply to author
Forward
0 new messages