[Python-Dev] setUpClass and setUpModule in unittest (original) (raw)

Tres Seaver tseaver at palladion.com
Thu Feb 11 17🔞51 CET 2010


-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1

Olemis Lang wrote:

On Tue, Feb 9, 2010 at 8:10 PM, Ben Finney <ben+python at benfinney.id.au> wrote:

Michael Foord <fuzzyman at voidspace.org.uk> writes:

I've used unittest for long running functional and integration tests (in both desktop and web applications). The infrastructure it provides is great for this. Don't get hung up on the fact that it is called unittest. In fact for many users the biggest reason it isn't suitable for tests like these is the lack of shared fixture support - which is why the other Python test frameworks provide them and we are going to bring it into unittest. I would argue that one of the things that makes ‘unittest’ good is that it makes it difficult to do the wrong thing — or at least this wrong thing. Fixtures persist for the lifetime of a single test case, and no more; that's the way unit tests should work. Making the distinction clearer by using a different API (and not extending the ‘unittest’ API) seems to be the right way to go. If that means that development should be focused on including mechanisms to make unittest more extensible instead of complicating the current «relatively simple» API , then I agree . I think about unittest as a framework for writing test cases; but OTOH as a meta-framework to be used as the basic building blocks to build or integrate third-party testing infrastructures (and that includes third-party packages ;o)

Just as a point of reference: zope.testing[1] has a "layer" feature which is used to support this usecase: a layer is a class namedd as an attribute of a testcase, e.g.:

class FunctionalLayer: @classmethod def setUp(klass): """ Do some expesnive shared setup. """ @classmethod def tearDown(klass): """ Undo the expensive setup. """

class MyTest(unittest.TestCase): layer = FunctionalLayer

The zope.testing testrunner groups testcase classes together by layer: each layer's setUp is called, then the testcases for that layer are run, then the layer's tearDown is called.

Other features:

These features has been in heavy use for about 3 1/2 years with a lot of success.

[1] http://pypi.python.org/pypi/zope.testing/

Tres. - --

Tres Seaver +1 540-429-0999 tseaver at palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkt0LeYACgkQ+gerLs4ltQ57WgCdFTzc1OHocXj/WTLShP62Q1bx vSAAnAqE/9+o1tZAaSLzlXfxaoRGTiuf =O/b2 -----END PGP SIGNATURE-----



More information about the Python-Dev mailing list