TEST: Use addCleanup in test_nbconvert_handlers.py

This guarantees that resources are cleaned up correctly even if setUp
fails.
This commit is contained in:
Scott Sanderson 2016-06-18 14:38:49 -04:00
parent c188b0ad42
commit 34ef078b00

View File

@ -58,7 +58,16 @@ class APITest(NotebookTestBase):
nbdir = self.notebook_dir.name
if not os.path.isdir(pjoin(nbdir, 'foo')):
os.mkdir(pjoin(nbdir, 'foo'))
subdir = pjoin(nbdir, 'foo')
os.mkdir(subdir)
# Make sure that we clean this up when we're done.
# By using addCleanup this will happen correctly even if we fail
# later in setUp.
@self.addCleanup
def cleanup_dir():
shutil.rmtree(subdir, ignore_errors=True)
nb = new_notebook()
@ -77,12 +86,6 @@ class APITest(NotebookTestBase):
self.nbconvert_api = NbconvertAPI(self.base_url())
def tearDown(self):
nbdir = self.notebook_dir.name
for dname in ['foo']:
shutil.rmtree(pjoin(nbdir, dname), ignore_errors=True)
@onlyif_cmds_exist('pandoc')
def test_from_file(self):
r = self.nbconvert_api.from_file('html', 'foo', 'testnb.ipynb')