-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #28 - stops breaking `--failed-first` flag.
- Loading branch information
Showing
8 changed files
with
205 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
try: | ||
from collections import OrderedDict | ||
except ImportError: | ||
from ordereddict import OrderedDict | ||
import functools | ||
|
||
bucket_type_keys = OrderedDict() | ||
|
||
|
||
def bucket_type_key(bucket_type): | ||
""" | ||
Registers a function that calculates test item key for the specified bucket type. | ||
""" | ||
|
||
def decorator(f): | ||
|
||
@functools.wraps(f) | ||
def wrapped(item, session): | ||
key = f(item) | ||
|
||
if session is not None: | ||
for handler in session.pytest_random_order_bucket_type_key_handlers: | ||
key = handler(item, key) | ||
|
||
return key | ||
|
||
bucket_type_keys[bucket_type] = wrapped | ||
return wrapped | ||
|
||
return decorator | ||
|
||
|
||
@bucket_type_key('global') | ||
def get_global_key(item): | ||
return None | ||
|
||
|
||
@bucket_type_key('package') | ||
def get_package_key(item): | ||
return item.module.__package__ | ||
|
||
|
||
@bucket_type_key('module') | ||
def get_module_key(item): | ||
return item.module.__name__ | ||
|
||
|
||
@bucket_type_key('class') | ||
def get_class_key(item): | ||
if item.cls: | ||
return item.module.__name__, item.cls.__name__ | ||
else: | ||
return item.module.__name__ | ||
|
||
|
||
@bucket_type_key('parent') | ||
def get_parent_key(item): | ||
return item.parent | ||
|
||
|
||
@bucket_type_key('grandparent') | ||
def get_grandparent_key(item): | ||
return item.parent.parent | ||
|
||
|
||
@bucket_type_key('none') | ||
def get_none_key(item): | ||
raise RuntimeError('When shuffling is disabled (bucket_type=none), item key should not be calculated') | ||
|
||
|
||
bucket_types = bucket_type_keys.keys() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
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 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.pytest_random_order_bucket_type_key_handlers.append(assign_last_failed_to_same_bucket) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import codecs | ||
import os | ||
|
||
from setuptools import setup | ||
|
||
|
||
|
@@ -13,7 +14,7 @@ def read(fname): | |
|
||
setup( | ||
name='pytest-random-order', | ||
version='0.7.0', | ||
version='0.8.0', | ||
author='Jazeps Basko', | ||
author_email='[email protected]', | ||
maintainer='Jazeps Basko', | ||
|
@@ -22,7 +23,12 @@ def read(fname): | |
url='https://github.com/jbasko/pytest-random-order', | ||
description='Randomise the order in which pytest tests are run with some control over the randomness', | ||
long_description=read('README.rst'), | ||
py_modules=['pytest_random_order.plugin', 'pytest_random_order.shuffler'], | ||
py_modules=[ | ||
'pytest_random_order.bucket_types', | ||
'pytest_random_order.cache', | ||
'pytest_random_order.plugin', | ||
'pytest_random_order.shuffler', | ||
], | ||
install_requires=['pytest>=2.9.2'], | ||
classifiers=[ | ||
'Development Status :: 5 - Production/Stable', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters