From e5f06c98d411f24e93050ac0da558fb3bcfeefe1 Mon Sep 17 00:00:00 2001 From: John Didion Date: Wed, 29 May 2024 15:51:51 -0700 Subject: [PATCH] Fix unbound local variable error If the call to open stdout or stderr files, the corresponding variable will be unbound and result in an error. --- src/pytest_workflow/workflow.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pytest_workflow/workflow.py b/src/pytest_workflow/workflow.py index 748b0244..5f663c5f 100644 --- a/src/pytest_workflow/workflow.py +++ b/src/pytest_workflow/workflow.py @@ -79,6 +79,8 @@ def start(self): # is started from multiple threads. with self.start_lock: if not self._started: + stdout_h = None + stderr_h = None try: stdout_h = self.stdout_file.open('wb') stderr_h = self.stderr_file.open('wb') @@ -91,8 +93,10 @@ def start(self): self.errors.append(error) finally: self._started = True - stdout_h.close() - stderr_h.close() + if stdout_h is not None: + stdout_h.close() + if stderr_h is not None: + stderr_h.close() else: raise ValueError("Workflows can only be started once")