File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,6 +58,32 @@ def _vcr_outcome_gate(request, vcr):
5858def pytest_configure (config ):
5959 _verbose_state .remember_pluginmanager (config )
6060 reset_vcr_diag_dir ()
61+ _flush_corrupted_presidio_cassettes ()
62+
63+
64+ def _flush_corrupted_presidio_cassettes () -> None :
65+ if os .environ .get ("PYTEST_XDIST_WORKER" ):
66+ return
67+ url = os .environ .get ("CASSETTE_REDIS_URL" )
68+ if not url :
69+ return
70+ try :
71+ import redis
72+
73+ client = redis .Redis .from_url (
74+ url , socket_timeout = 5 , socket_connect_timeout = 5
75+ )
76+ pattern = "litellm:vcr:cassette:tests/guardrails_tests/test_presidio_pii/*"
77+ deleted = 0
78+ for key in client .scan_iter (match = pattern , count = 500 ):
79+ client .delete (key )
80+ deleted += 1
81+ print (
82+ f"[flush-hack] deleted { deleted } presidio cassettes from redis" ,
83+ flush = True ,
84+ )
85+ except Exception as exc :
86+ print (f"[flush-hack] failed: { exc } " , flush = True )
6187
6288
6389def pytest_runtest_logreport (report ):
You can’t perform that action at this time.
0 commit comments