From 4398ba1063780d90edf8a3b3b91c47f855f33c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3n=C3=A1n=20Carrigan?= Date: Thu, 16 Feb 2023 09:19:15 +0000 Subject: [PATCH] fix(unittest): handle error outside of file If an error occurs outside of the test file, there is no frame to match an error to. This can happen for example when required arguments are not passed to the test. --- neotest_python/unittest.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/neotest_python/unittest.py b/neotest_python/unittest.py index 6c58aeb..d5d45ec 100644 --- a/neotest_python/unittest.py +++ b/neotest_python/unittest.py @@ -72,11 +72,10 @@ class UnittestNeotestAdapter(NeotestAdapter): if case_id in errs: trace = errs[case_id][2] summary = traceback.extract_tb(trace) - error_line = next( - frame.lineno - 1 - for frame in reversed(summary) - if frame.filename == case_file - ) + for frame in reversed(summary): + if frame.filename == case_file: + error_line = frame.lineno - 1 + break results[case_id] = { "status": NeotestResultStatus.FAILED, "errors": [{"message": message, "line": error_line}],