38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from pathlib import Path
|
|
import pytest
|
|
|
|
def test_no_op_without_registry(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.chdir(tmp_path)
|
|
(tmp_path / "test_zz.py").write_text(
|
|
"def test_b(): pass\ndef test_a(): pass\n", encoding="utf-8"
|
|
)
|
|
from pytest_collection_order import sort_items_by_order
|
|
items = []
|
|
result = sort_items_by_order(items, registry_path=tmp_path / "reg.toml")
|
|
assert result == items
|
|
|
|
def test_sorts_by_order_index(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.chdir(tmp_path)
|
|
(tmp_path / "test_zz.py").write_text(
|
|
"def test_b(): pass\ndef test_a(): pass\n", encoding="utf-8"
|
|
)
|
|
reg = tmp_path / "reg.toml"
|
|
reg.write_text(
|
|
"[[files.test_zz.test_order]]\n"
|
|
"test_id = 'test_zz::test_b'\n"
|
|
"order = 1\n"
|
|
"[[files.test_zz.test_order]]\n"
|
|
"test_id = 'test_zz::test_a'\n"
|
|
"order = 2\n",
|
|
encoding="utf-8",
|
|
)
|
|
class _Item:
|
|
def __init__(self, nodeid: str) -> None:
|
|
self.nodeid = nodeid
|
|
def __repr__(self) -> str:
|
|
return f"_Item({self.nodeid!r})"
|
|
items = [_Item("test_zz::test_b"), _Item("test_zz::test_a")]
|
|
from pytest_collection_order import sort_items_by_order
|
|
result = sort_items_by_order(items, registry_path=reg)
|
|
assert [i.nodeid for i in result] == ["test_zz::test_b", "test_zz::test_a"]
|