Combine class and method name when saving work dir

In the Python version when saving the work directory for a failed test
case, create a path based on both the class and method name.
This commit is contained in:
Håkan Thörngren 2016-01-03 19:53:00 -08:00
parent af28746648
commit 5075c7b38b

View File

@ -527,6 +527,7 @@ class Tmpdir:
self.environ_path = os.environ['PATH'] self.environ_path = os.environ['PATH']
self.old_cwds = [] self.old_cwds = []
self.remove_all_preserve() self.remove_all_preserve()
self.test_method_name = None
def stdout_log(self): def stdout_log(self):
return os.path.join(self.logdir, "tmp.stdout") return os.path.join(self.logdir, "tmp.stdout")
@ -540,6 +541,10 @@ class Tmpdir:
def snapshot(self): def snapshot(self):
return FsSnapshot(self.top) return FsSnapshot(self.top)
def prepare_for_test(self, test_method_name):
self.clear()
self.test_method_name = test_method_name
def clear(self): def clear(self):
if os.path.exists(self.top): if os.path.exists(self.top):
shutil.rmtree(self.top) shutil.rmtree(self.top)
@ -549,8 +554,10 @@ class Tmpdir:
if os.path.exists(self.top_save): if os.path.exists(self.top_save):
shutil.rmtree(self.top_save) shutil.rmtree(self.top_save)
def preserve(self, name): def preserve(self, test_class_name):
shutil.move(self.top, os.path.join(self.top_save, name)) shutil.move(self.top, os.path.join(self.top_save,
test_class_name,
self.test_method_name))
def __enter__(self): def __enter__(self):
self.old_cwds.append(os.getcwd()) self.old_cwds.append(os.getcwd())
@ -575,7 +582,7 @@ class Tmethod:
def run(self, tmpdir, statistics): def run(self, tmpdir, statistics):
obj = self.tclass.klass(tmpdir, statistics) obj = self.tclass.klass(tmpdir, statistics)
tmpdir.clear() tmpdir.prepare_for_test(self.name())
with tmpdir: with tmpdir:
try: try:
obj.setup() obj.setup()