test(collection_order): add red tests for opt-in sort_items_by_order
This commit is contained in:
@@ -0,0 +1,37 @@
|
|||||||
|
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"]
|
||||||
Reference in New Issue
Block a user