From 6f6fe876e25a41cc8b5eba1d9db5a609457cb937 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 7 Nov 2022 10:45:53 +0100 Subject: [PATCH] Fix parameter missing in Python 3.7 --- novelwriter/core/document.py | 8 ++++++-- tests/test_core/test_core_project.py | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/novelwriter/core/document.py b/novelwriter/core/document.py index 2d609538..2f04c128 100644 --- a/novelwriter/core/document.py +++ b/novelwriter/core/document.py @@ -201,8 +201,12 @@ class NWDoc: docTemp = docPath.with_suffix(".tmp") try: - docPath.unlink(missing_ok=True) - docTemp.unlink(missing_ok=True) + # ToDo: When Python 3.7 is dropped, these can be changed to + # path.unlink(missing_ok=True) + if docPath.exists(): + docPath.unlink() + if docTemp.exists(): + docTemp.unlink() except Exception as exc: self._docError = formatException(exc) return False diff --git a/tests/test_core/test_core_project.py b/tests/test_core/test_core_project.py index 62e631c3..368a7ddb 100644 --- a/tests/test_core/test_core_project.py +++ b/tests/test_core/test_core_project.py @@ -582,7 +582,8 @@ def testCoreProject_Methods(monkeypatch, mockGUI, fncDir, mockRnd): # Write entry statsFile = theProject.storage.getMetaFile(nwFiles.SESS_STATS) assert isinstance(statsFile, Path) - statsFile.unlink(missing_ok=True) + if statsFile.exists(): + statsFile.unlink() theProject._projOpened = 1600002000 theProject.data._initCounts = [50, 50]