From 77235e2759085dc7e9bb572f8a4e65f9aa079ae1 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 3 Jun 2021 08:45:01 -0700 Subject: [PATCH] Revert "Merge pull request #8227 from encukou/defensive-get_source" This reverts commit 67af623d9e25716cf7bb91dd6ce7354991197954, reversing changes made to aead41e449b07d00c958b938d899841f304dc2fa. --- src/_pytest/_code/code.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index d9a6b9edb..2fdd8a086 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -725,11 +725,11 @@ class FormattedExcinfo: ) -> List[str]: """Return formatted and marked up source lines.""" lines = [] - if source is not None and line_index < 0: - line_index += len(source.lines) - if source is None or line_index >= len(source.lines) or line_index < 0: + if source is None or line_index >= len(source.lines): source = Source("???") line_index = 0 + if line_index < 0: + line_index += len(source) space_prefix = " " if short: lines.append(space_prefix + source.lines[line_index].strip())