From fd11351859233727538fa47213df7c7c9821d9e0 Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Sat, 1 Sep 2007 16:36:01 -0700 Subject: Use separate temp directories for separate tests. Makes unit tests for the previous commit work even when not run alone. Should have done this from the beginning, but didn't find the trick for getting the module name. --- gitosis/test/test_repository.py | 3 --- gitosis/test/util.py | 20 +++++++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/gitosis/test/test_repository.py b/gitosis/test/test_repository.py index 2ac0d79..c9fbc58 100644 --- a/gitosis/test/test_repository.py +++ b/gitosis/test/test_repository.py @@ -1,7 +1,6 @@ from nose.tools import eq_ as eq import os -import shutil from gitosis import repository @@ -39,8 +38,6 @@ def test_init_exist_git(): def test_init_templates(): tmp = maketemp() path = os.path.join(tmp, 'repo.git') - if os.path.exists(path): - shutil.rmtree(path) templatedir = os.path.join( os.path.dirname(__file__), 'mocktemplates', diff --git a/gitosis/test/util.py b/gitosis/test/util.py index b37178e..aa5a4a2 100644 --- a/gitosis/test/util.py +++ b/gitosis/test/util.py @@ -2,7 +2,9 @@ from nose.tools import eq_ as eq import errno import os +import shutil import stat +import sys def mkdir(*a, **kw): try: @@ -16,9 +18,21 @@ def mkdir(*a, **kw): def maketemp(): tmp = os.path.join(os.path.dirname(__file__), 'tmp') mkdir(tmp) - me = os.path.splitext(os.path.basename(__file__))[0] - tmp = os.path.join(tmp, me) - mkdir(tmp) + + caller = sys._getframe(1) + name = '%s.%s' % ( + sys._getframe(1).f_globals['__name__'], + caller.f_code.co_name, + ) + tmp = os.path.join(tmp, name) + try: + shutil.rmtree(tmp) + except OSError, e: + if e.errno == errno.ENOENT: + pass + else: + raise + os.mkdir(tmp) return tmp def writeFile(path, content): -- cgit v1.2.3