diff options
author | Julien Cristau <julien.cristau@logilab.fr> | 2013-02-22 09:46:41 +0100 |
---|---|---|
committer | Julien Cristau <julien.cristau@logilab.fr> | 2013-02-22 09:46:41 +0100 |
commit | f3fbd3b38a8624c83e6f13616947c2775f194cac (patch) | |
tree | a16c08a331cc065931d6715ea6a60aafc58d14dd /test | |
parent | 6d1c386f313a6c88d3ea4e5ba612266dbac2c362 (diff) | |
download | logilab-common-f3fbd3b38a8624c83e6f13616947c2775f194cac.tar.gz |
[testlib] check for generators in with_tempdir
If the decorated callable is a generator, we shouldn't reset tempfile.tempdir
until the end of the iteration. Hopefully nobody uses this with nested/chained
generators, or they'd stomp all over each other's tempdirs.
Closes #117533
Diffstat (limited to 'test')
-rw-r--r-- | test/unittest_testlib.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/test/unittest_testlib.py b/test/unittest_testlib.py index 4ea8242..f83e1f2 100644 --- a/test/unittest_testlib.py +++ b/test/unittest_testlib.py @@ -628,6 +628,17 @@ class DecoratorTC(TestCase): self.assertListEqual(list(os.walk(tempdir)), [(tempdir, [], [])]) + def test_tmpdir_generator(self): + orig_tempdir = tempfile.gettempdir() + + @with_tempdir + def gen(): + yield tempfile.gettempdir() + + for tempdir in gen(): + self.assertNotEqual(orig_tempdir, tempdir) + self.assertEqual(orig_tempdir, tempfile.gettempdir()) + def setUp(self): self.pyversion = sys.version_info |