Apache Mod-Python - Re: Grouping tests

This is Interesting: Free IT Magazines  
Home > Archive > Apache Mod-Python > March 2006 > Re: Grouping tests





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: Grouping tests
Jim Gallacher

2006-03-31, 12:03 am

This isn't too different from what I have in mind, except that my main
testrunner.py script uses introspection to discover the tests. Adding a
new test set won't require editing testrunner at all. The testrunner
will also filter the tests according to certain criteria, such as mpm or
os, so that tests for a specific platform are automatically selected.

More later.

Jim


Mike Looijmans wrote:
> What I have been doing in a totally unrelated Python project is to
> create test groups simply by putting them into separate modules. The
> main test module test.py looks like this:
>
> ## (test.py)
> import unittest
> from test_something import *
> from test_someother import *
> from test_yetmore import *
> if __name__ == '__main__':
> unittest.main(module=__import__(__name__))
> ##
>
> This works because unittest takes all 'things' that start with 'test' in
> the provided module and runs them. So anything we bring into our
> namespace gets run. This also makes it possible to import tests from
> other projects, and share these tests between projects.
> The other test_ modules look much alike:
>
> ## (test_something.py)
> import unittest
> import test_peer
> class test04MultiPeerSystem(test_peer.BaseTestRealThing):
> def test03DiscoveryC08B20(self):
> "Multiple clients w/ discovery: 8 peers, 20 blocks each"
> self.runDiscoveryTest(nclients = 8, nblocks=20)
> if __name__ == '__main__':
> unittest.main(module=__import__(__name__))
> ##
>
> This makes it very easy to handle test subsets, and run single test
> suites. Just run
>
> $python test.py
>
> to run ALL the tests. To run just a single set, run
>
> $python test_something.py
>
> And to run a single test, either of these will do:
>
> $python test_something.py test04MultiPeerSystem
> $python test.py test04MultiPeerSystem
>
> The real power shows when you want to run 4 or 5 test sets, and/or only
> parts of some test sets. Just create a new "main" test unit that imports
> the desired ones, and you're set:
>
> ## (test_few.py)
> import unittest
> from test_something import *
> from test_someother import TestOnlyThis
> if __name__ == '__main__':
> unittest.main(module=__import__(__name__))
> ##
>
> Because some tests take very long to run (in my vocabulary, "long" means
> more than a second), this saves me a lot of time when working on a part
> of a big project, where I don't need to run all tests all the time.
>
> --
> Mike Looijmans
> Philips Natlab / Topic Automation
>
>
> Jim Gallacher wrote:
> ...
>
>
>
>



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com