Skip to content

Commit

Permalink
fix(blame): use fail line instead of test line (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
caioariede authored Oct 14, 2024
1 parent 8bbb011 commit deccb4e
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/pytest_xflaky/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
)

Expand Down

0 comments on commit deccb4e

Please sign in to comment.