mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
clean up temporary dirs in tearDown to force cleanup even if tests fail
This commit is contained in:
parent
a8983b420f
commit
e82c6512b4
3 changed files with 69 additions and 75 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue