11import dataclasses
2+ import os
23import pytest
34import _pytest .nodes
45import requests
@@ -14,6 +15,9 @@ class Quarantine:
1415 quarantined_tests : typing .List [str ] = dataclasses .field (
1516 init = False , default_factory = list
1617 )
18+ quarantine_used_by_tests : typing .Set [str ] = dataclasses .field (
19+ init = False , default_factory = set
20+ )
1721 init_error_msg : typing .Optional [str ] = dataclasses .field (init = False , default = None )
1822
1923 def __post_init__ (self ) -> None :
@@ -51,8 +55,31 @@ def __post_init__(self) -> None:
5155 def __contains__ (self , item : _pytest .nodes .Item ) -> bool :
5256 return item .nodeid in self .quarantined_tests
5357
54- @staticmethod
55- def mark_test_as_quarantined (test_item : _pytest .nodes .Item ) -> None :
58+ def quarantined_tests_report (self ) -> str :
59+ report_str = f"""🛡️ Quarantine
60+ - Repository: { self .repo_name }
61+ - Branch: { self .branch_name }
62+ - Quarantined tests fetched from API: { len (self .quarantined_tests )}
63+ """
64+
65+ if self .quarantine_used_by_tests :
66+ report_str += f"""
67+ - 🔒 Quarantined:
68+ · { f"{ os .linesep } · " .join (sorted (self .quarantine_used_by_tests ))}
69+ """
70+
71+ unused_quarantined_tests = (
72+ set (self .quarantined_tests ) - self .quarantine_used_by_tests
73+ )
74+ if unused_quarantined_tests :
75+ report_str += f"""
76+ - Unused quarantined tests:
77+ · { f"{ os .linesep } · " .join (sorted (unused_quarantined_tests ))}
78+ """
79+
80+ return report_str
81+
82+ def mark_test_as_quarantined (self , test_item : _pytest .nodes .Item ) -> None :
5683 test_item .add_marker (
5784 pytest .mark .xfail (
5885 reason = "Test is quarantined from Mergify CI Insights" ,
@@ -62,3 +89,4 @@ def mark_test_as_quarantined(test_item: _pytest.nodes.Item) -> None:
6289 ),
6390 append = True ,
6491 )
92+ self .quarantine_used_by_tests .add (test_item .nodeid )
0 commit comments