2019-04-19 07:23:08 +08:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
|
2019-04-08 01:08:59 +08:00
|
|
|
def pytest_collection_modifyitems(config, items):
|
2019-04-19 07:23:08 +08:00
|
|
|
"""Prefer faster tests.
|
|
|
|
|
|
|
|
Use a hookwrapper to do this in the beginning, so e.g. --ff still works
|
|
|
|
correctly.
|
|
|
|
"""
|
2019-04-08 01:08:59 +08:00
|
|
|
fast_items = []
|
|
|
|
slow_items = []
|
2019-05-27 09:20:58 +08:00
|
|
|
slowest_items = []
|
2019-04-08 01:08:59 +08:00
|
|
|
neutral_items = []
|
|
|
|
|
2019-05-27 09:20:58 +08:00
|
|
|
spawn_names = {"spawn_pytest", "spawn"}
|
2019-04-08 01:08:59 +08:00
|
|
|
|
|
|
|
for item in items:
|
|
|
|
try:
|
|
|
|
fixtures = item.fixturenames
|
|
|
|
except AttributeError:
|
|
|
|
# doctest at least
|
|
|
|
# (https://github.com/pytest-dev/pytest/issues/5070)
|
|
|
|
neutral_items.append(item)
|
|
|
|
else:
|
2019-05-27 09:20:58 +08:00
|
|
|
if "testdir" in fixtures:
|
|
|
|
if spawn_names.intersection(item.function.__code__.co_names):
|
|
|
|
item.add_marker(pytest.mark.uses_pexpect)
|
2019-05-30 03:30:45 +08:00
|
|
|
slowest_items.append(item)
|
2019-05-27 09:20:58 +08:00
|
|
|
else:
|
2019-05-30 03:30:45 +08:00
|
|
|
slow_items.append(item)
|
2019-05-30 12:55:38 +08:00
|
|
|
item.add_marker(pytest.mark.slow)
|
2019-04-08 01:08:59 +08:00
|
|
|
else:
|
|
|
|
marker = item.get_closest_marker("slow")
|
|
|
|
if marker:
|
2019-05-27 09:20:58 +08:00
|
|
|
slowest_items.append(item)
|
2019-04-08 01:08:59 +08:00
|
|
|
else:
|
|
|
|
fast_items.append(item)
|
|
|
|
|
2019-05-30 03:30:45 +08:00
|
|
|
items[:] = fast_items + neutral_items + slow_items + slowest_items
|
2019-04-19 07:23:08 +08:00
|
|
|
|
|
|
|
yield
|