[#349] Fixed hook pytest-collect-modifyitems

Signed-off-by: Ilyas Niyazov <i.niyazov@yadro.com>
This commit is contained in:
Ilyas Niyazov 2025-01-17 17:37:51 +03:00
parent 80dd8d0b16
commit aed20e02ac
2 changed files with 18 additions and 3 deletions

View file

@ -1,4 +1,4 @@
__version__ = "2.0.1"
from .fixtures import configure_testlib, hosting, temp_directory
from .hooks import pytest_collection_modifyitems
from .hooks import pytest_add_frostfs_marker, pytest_collection_modifyitems

View file

@ -1,8 +1,8 @@
import pytest
@pytest.hookimpl
def pytest_collection_modifyitems(items: list[pytest.Item]):
@pytest.hookimpl(specname="pytest_collection_modifyitems")
def pytest_add_frostfs_marker(items: list[pytest.Item]):
# All tests which reside in frostfs nodeid are granted with frostfs marker, excluding
# nodeid = full path of the test
# 1. plugins
@ -11,3 +11,18 @@ def pytest_collection_modifyitems(items: list[pytest.Item]):
location = item.location[0]
if "frostfs" in location and "plugin" not in location and "testlib" not in location:
item.add_marker("frostfs")
# pytest hook. Do not rename
@pytest.hookimpl(trylast=True)
def pytest_collection_modifyitems(items: list[pytest.Item]):
# Change order of tests based on @pytest.mark.order(<int>) marker
def order(item: pytest.Item) -> int:
order_marker = item.get_closest_marker("order")
if order_marker and (len(order_marker.args) != 1 or not isinstance(order_marker.args[0], int)):
raise RuntimeError("Incorrect usage of pytest.mark.order")
order_value = order_marker.args[0] if order_marker else 0
return order_value
items.sort(key=lambda item: order(item))