From deccb4e782ec8b92d1dba438344e0101eb68558a Mon Sep 17 00:00:00 2001 From: Caio Ariede Date: Mon, 14 Oct 2024 08:29:05 -0300 Subject: [PATCH] fix(blame): use fail line instead of test line (#18) --- src/pytest_xflaky/plugin.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/pytest_xflaky/plugin.py b/src/pytest_xflaky/plugin.py index 2c9ea25..99a40ee 100644 --- a/src/pytest_xflaky/plugin.py +++ b/src/pytest_xflaky/plugin.py @@ -23,16 +23,17 @@ class XflakyAction(enum.Enum): @dataclass class Test: nodeid: str - lineno: int + faillineno: int + testlineno: int def __str__(self): - return f"{self.nodeid}:{self.lineno}" + return f"{self.nodeid}:{self.faillineno}" def __hash__(self): return hash(str(self)) def __eq__(self, other): - return other.nodeid == self.nodeid and other.lineno == self.lineno + return other.nodeid == self.nodeid and other.faillineno == self.faillineno def get_filename(self): if "::" in self.nodeid: @@ -101,8 +102,8 @@ def write(self, tests: list[MaybeFlakyTest], flaky: int): data["is_flaky"] = maybe_flaky_test.is_flaky() if data["is_flaky"]: filename = maybe_flaky_test.test.get_filename() - lineno = maybe_flaky_test.test.lineno - data["blame"] = github_blame.blame(filename, lineno) + faillineno = maybe_flaky_test.test.faillineno + data["blame"] = github_blame.blame(filename, faillineno) if data["blame"]: report_key = data["blame"]["github_username"] else: @@ -233,8 +234,17 @@ def iter_parse_file(self, filename): with open(f"{self.directory}/{filename}") as f: data = json.load(f) for test in data["tests"]: + testlineno = test["lineno"] + try: + faillineno = test["call"]["traceback"][0]["lineno"] + except (KeyError, IndexError): + faillineno = testlineno yield ( - Test(nodeid=test["nodeid"], lineno=test["lineno"]), + Test( + nodeid=test["nodeid"], + testlineno=testlineno, + faillineno=faillineno, + ), test["outcome"] in outcomes, )