Skip to content

Commit fadf4a9

Browse files
committed
Improve solution for windows bug with tempfiles.
Solution previously was applied to all OS and was not windows specific. This update makes is windows specific.
1 parent cfca559 commit fadf4a9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tests/test_notebooks.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,14 @@ def dynamic_analysis(self, path, kernel_name):
318318

319319
# Execute the notebook and allow errors (run all cells), output is
320320
# written to a temporary file which is automatically deleted.
321-
# The delete=False is here to address an issue that Windows has with temporary files.
322-
# On windows, if delete=True the file is kept open and cannot be read from.
321+
# Windows has a bug with temporary files. On windows, if delete=True
322+
# the file is kept open and cannot be read from
323323
# (see https://github.com/python/cpython/issues/58451).
324-
with tempfile.NamedTemporaryFile(suffix=".ipynb", delete=False) as fout:
324+
# We set the delete flag to False on windows and True on all
325+
# other operating systems, circumventing the issue.
326+
with tempfile.NamedTemporaryFile(
327+
suffix=".ipynb", delete=os.name != "nt"
328+
) as fout:
325329
output_dir, output_fname = os.path.split(fout.name)
326330
args = [
327331
"jupyter",

0 commit comments

Comments
 (0)