clean up temporary dirs in tearDown to force cleanup even if tests fail

This commit is contained in:
Bruno Binet 2012-05-12 02:03:18 +02:00
commit e82c6512b4
3 changed files with 69 additions and 75 deletions

View file

@ -1,14 +1,10 @@
__all__ = [
'temporary_folder',
'get_article',
'unittest',
]
import os
import subprocess
from contextlib import contextmanager
from tempfile import mkdtemp
from shutil import rmtree
from pelican.contents import Article
@ -18,20 +14,6 @@ except ImportError:
import unittest
@contextmanager
def temporary_folder():
"""creates a temporary folder, return it and delete it afterwards.
This allows to do something like this in tests:
>>> with temporary_folder() as d:
# do whatever you want
"""
tempdir = mkdtemp()
yield tempdir
rmtree(tempdir)
def get_article(title, slug, content, lang, extra_metadata=None):
metadata = {'slug': slug, 'title': title, 'lang': lang}
if extra_metadata is not None: