File: cache.py

package info (click to toggle)
python-pytest-random-order 1.1.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 276 kB
  • sloc: python: 704; makefile: 12; sh: 6
file content (39 lines) | stat: -rw-r--r-- 1,116 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
This module is called "cache" because it builds on the "cache" plugin:

    https://docs.pytest.org/en/latest/cache.html

"""

FAILED_FIRST_LAST_FAILED_BUCKET_KEY = '<failed_first_last_failed>'


def process_failed_first_last_failed(session, config, items):
    if not hasattr(config, 'cache'):
        return

    if not config.getoption('failedfirst'):
        return

    last_failed_raw = config.cache.get('cache/lastfailed', None)
    if not last_failed_raw:
        return

    # Get the names of last failed tests
    last_failed = []
    for key in last_failed_raw.keys():
        parts = key.split('::')
        if len(parts) == 3:
            last_failed.append(tuple(parts))
        elif len(parts) == 2:
            last_failed.append((parts[0], None, parts[1]))
        else:
            raise NotImplementedError()

    def assign_last_failed_to_same_bucket(item, key):
        if item.nodeid in last_failed_raw:
            return FAILED_FIRST_LAST_FAILED_BUCKET_KEY
        else:
            return key

    session.random_order_bucket_type_key_handlers.append(assign_last_failed_to_same_bucket)