Skip to content

Commit

Permalink
use pytest.exit
Browse files Browse the repository at this point in the history
  • Loading branch information
caioariede committed Sep 17, 2024
1 parent 2d51ebc commit c56631a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/pytest_xflaky/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ def generate_report(self):
min_failures=self.config.option.xflaky_min_failures,
)

flaky_tests = finder.run()
flaky_tests, total_tests = finder.run()
if flaky_tests:
self.print_report(flaky_tests)
pytest.exit(1)
pytest.exit(
f"Flaky tests found: {flaky_tests}/{total_tests}", return_code=1
)

print("No flaky tests found")
pytest.exit("No flaky tests found", return_code=0)

def print_report(self, flaky_tests):
for flaky_test in flaky_tests:
Expand All @@ -96,7 +98,9 @@ def __init__(self, *, directory: str, min_failures: int):
def run(self) -> list[FlakyTest]:
ok = {}
failures = {}
total = 0
for test, failure in self.collect_tests():
total += 1
if failure:
failures.setdefault(test, 0)
failures[test] += 1
Expand All @@ -113,7 +117,7 @@ def run(self) -> list[FlakyTest]:
FlakyTest(test=test, ok=ok_, failed=failures[test])
)

return flaky_tests
return flaky_tests, total

def collect_tests(self):
for f in os.listdir(self.directory):
Expand Down

0 comments on commit c56631a

Please sign in to comment.