[TIP] nose TestSuite discovery & reusable test design

Brian Beck exogen at gmail.com
Sat May 23 09:52:47 PDT 2009

Hi list,

A couple questions.  I tried searching for this first one with no
luck, so I apologize if this comes up often:

- I can't get Nose 0.11.1 to play well with unittest.TestSuite
instances, both in discovery and in running.  If I do this:

test_suite = TestSuite()
test_suite.addTests(...generate some sequence of TestCases...)

...then I find it odd that Nose doesn't discover that TestSuite
instance.  If I do this:

def test_suite():
    suite = TestSuite()
    suite.addTests(...generate some sequence of TestCases...)
    return suite

...then Nose will discover and run the "suite", but really just
considers it a single test, instead of my expected behavior of
reporting on all tests in the suite.

My second question reveals why I want to use a TestSuite and generate
TestCase instances.  I'm writing helpers for running the Data Access
Working Group's SPARQL test suite [1].  The test suite is modeled in
RDF and individual tests are collected in manifests.  An example: one
type if test is a syntax test (for testing a SPARQL query parser), so
there is a syntax test manifest describing only those.  I have
ManifestTestSuite and SyntaxTestCase classes that know how to read and
run these.

My question is about reusability.  These helpers could be used by
anyone testing their SPARQL parser or engine.  Is there a common
pattern for connecting reusable test classes to the objects under
test?  My current code looks like this:

syntax_suite = ManifestTestSuite()
syntax_suite.configure(parser=parse_callable, failure_exception=ParseError)

My `configure` method just sets `parser` and `failure_exception`
attributes used by the tests.  These are the parts that could be
replaced with anyone's SPARQL parser.  But is there an existing
pattern for sending the objects under test to pre-built tests?


[1] http://www.w3.org/2001/sw/DataAccess/tests/r2

Brian Beck / Adventurer of the First Order / www.brianbeck.com
Unstoppable Rocket, LLC / www.unstoppablerocket.com

More information about the testing-in-python mailing list