~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/testing/__init__.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-12-02 01:27:41 UTC
  • mfrom: (14396.7.14 nest-temp-files)
  • Revision ID: launchpad@pqm.canonical.com-20111202012741-qxx3enakaxwkbk8x
[r=jcsackett][no-qa] New fixture NestedTempfile to temporarily move
        tempfile's default tempdir location itself to a temporary directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1289
1289
    return launchpad.load(canonical_url(obj, request=api_request))
1290
1290
 
1291
1291
 
 
1292
class NestedTempfile(fixtures.Fixture):
 
1293
    """Nest all temporary files and directories inside a top-level one."""
 
1294
 
 
1295
    def setUp(self):
 
1296
        super(NestedTempfile, self).setUp()
 
1297
        tempdir = fixtures.TempDir()
 
1298
        self.useFixture(tempdir)
 
1299
        patch = fixtures.MonkeyPatch("tempfile.tempdir", tempdir.path)
 
1300
        self.useFixture(patch)
 
1301
 
 
1302
 
1292
1303
@contextmanager
1293
1304
def temp_dir():
1294
1305
    """Provide a temporary directory as a ContextManager."""