On Tue, May 4, 2010 at 2:33 PM, Aaron Bentley <[email protected]> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 05/03/2010 09:47 PM, Tim Penhey wrote: >> This uses a Fixture that jml wrote a while ago for the scanner (which has >> since been removed). The fixture code was moved to lp.testing.fixture. If >> you >> have a need to use something in your tests that has a setUp and tearDown, you >> can define a fixture, and use the TestCase method installFixture. > > This sounds a lot like a Context Manager. Should they be unified? If > not, how should we choose which to use? >
They serve a similar purpose, to be sure. Please forgive me, but the best way I can answer right now is to think out loud and not come to a conclusion. I hope it helps. A bunch of things have setUp and tearDown methods, things like bzr Server objects. Some of these things are relatively complicated and benefit from having an addCleanup method. Hence, the Fixture base class. I'm going to call anything with a setUp and tearDown method a fixture for the rest of this email. Since these fixtures are frequently used in tests, it's nice to have a convenient way of saying "run this test with this fixture". Especially since "fixture.setUp(); self.addCleanup(fixture.tearDown)" is boilerplate. self.installFixture(FooFixture()) seems as good a way as any, especially in Python 2.4 land. In Python 2.5 land, we have Context Managers. I guess any test that uses addCleanup now (never mind Fixture) could be rewritten to use a context manager instead. I'm genuinely uncertain as to whether that would be an improvement, but guess not. It would certainly be nice to have something like installFixture that takes a Context Manager instead of a thing that has setUp and tearDown. It would probably be nice to have a thing that adapts objects with setUp/tearDown and turns them into Context Managers, since it would eliminate the need for two methods that do basically the same thing, and since it would let us use things like bzr Servers with the 'with' notation. Maybe Launchpad classes that have setUp and tearDown (like Fixture) should be changed to be context managers. I genuinely don't know whether that would be an improvement. I don't really know how many we have (excluding tests). I also don't know how many context managers we have. jml _______________________________________________ Mailing list: https://launchpad.net/~launchpad-dev Post to : [email protected] Unsubscribe : https://launchpad.net/~launchpad-dev More help : https://help.launchpad.net/ListHelp

