Skip to content

Instantly share code, notes, and snippets.

Created February 13, 2023 21:44
What would you like to do?
import os
import requests
def pytest_collection_modifyitems(session, config, items):
token = os.environ.get('TINYBIRD_TOKEN')
if not os.environ.get('GITLAB_CI'):
return items
response = requests.get(f'{token}')
if response.status_code != 200:
print("Error while sorting tests from tinybird")
modules_order = response.json()['data'][0]['items']
module_mapping = {item: item.cls.__name__ for item in items if item.cls}
modules = list(set(module_mapping.values()))
modules_oo = []
for module in modules_order:
if module in modules:
sorted_items = items.copy()
# Iteratively move tests of each module to the end of the test queue
for module in modules_oo:
sorted_items = [it for it in sorted_items if module_mapping.get(it, None) != module] + [
it for it in sorted_items if module_mapping.get(it, None) == module
items[:] = sorted_items
return items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment