Debian Codegraph @

random_order/cache.py

raw symbols SCIP
1 """
2 This module is called "cache" because it builds on the "cache" plugin:
3
4 https://docs.pytest.org/en/latest/cache.html
5
6 """
7
8 FAILED_FIRST_LAST_FAILED_BUCKET_KEY = "<failed_first_last_failed>"
9
10
11 def process_failed_first_last_failed(session, config, items):
12 if not hasattr(config, "cache"):
13 return
14
15 if not config.getoption("failedfirst"):
16 return
17
18 last_failed_raw = config.cache.get("cache/lastfailed", None)
19 if not last_failed_raw:
20 return
21
22 # Get the names of last failed tests
23 last_failed = []
24 for key in last_failed_raw.keys():
25 parts = key.split("::")
26 if len(parts) == 3:
27 last_failed.append(tuple(parts))
28 elif len(parts) == 2:
29 last_failed.append((parts[0], None, parts[1]))
30 else:
31 raise NotImplementedError()
32
33 def assign_last_failed_to_same_bucket(item, key):
34 if item.nodeid in last_failed_raw:
35 return FAILED_FIRST_LAST_FAILED_BUCKET_KEY
36 else:
37 return key
38
39 session.random_order_bucket_type_key_handlers.append(assign_last_failed_to_same_bucket)