Coverage for tests/wallet/conftest.py: 96%
28 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 19:49 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 19:49 +0000
1from __future__ import annotations
3from typing import Any, Generator
5import pytest
7from utils import TestUtils
10@pytest.fixture(scope="session", autouse=True)
11def close_test_wallets() -> Generator[None, Any, None]:
12 """The wallet of each type is open for all the tests of its type, in all the files, and is closed at the end."""
13 yield
14 TestUtils.close_wallets()
17_SEND_TESTS = "tests/wallet/test_send.py"
19_WALLET_TYPES = ("TestMoneroWalletFull", "TestMoneroWalletRpc", "TestMoneroWalletKeys")
20"""The classes of each type of wallet start with these, in the order that the types run."""
23def _is_wallet_test(item: pytest.Item) -> bool:
24 """A test of tests/wallet that is not about the models, which are unit tests that make nothing."""
25 return item.nodeid.startswith("tests/wallet/") and not item.nodeid.startswith("tests/wallet/model/")
28def _wallet_type_rank(item: pytest.Item) -> int:
29 """The place of the type of wallet that a test is for, in `_WALLET_TYPES`. The tests that are not for a type come after."""
30 parts: list[str] = item.nodeid.split("::")
31 test_class: str = parts[1] if len(parts) > 2 else ""
32 for rank, prefix in enumerate(_WALLET_TYPES):
33 if test_class.startswith(prefix):
34 return rank
35 return len(_WALLET_TYPES)
38def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
39 """The tests of tests/wallet run one type of wallet at a time, and the send tests first.
41 A file of a topic has a class for each type of wallet (full, rpc and keys), and the files run in alphabetical order, so the types
42 would alternate: the full wallet of a topic, the rpc wallet of the same one, and the next topic. The wallet of a type is the same for
43 all its tests, and the tests of a type use what the ones before made in it, so all the tests of a type run, and then the ones of
44 the next: as when they were in a class for each type.
46 Inside a type the send tests are the first. Some tests use what they made in the wallet: the proofs look for transactions with
47 outgoing destinations, and the ones of the payment ids for the transactions that were sent with one ("run send tests", they say). The
48 sends were the first tests when all of them were in a class, the relays tests, and test_proofs.py and test_txs.py come before
49 test_send.py in the alphabet.
51 Only the tests of tests/wallet move, in the places that they have: everything else stays where it was. It is a stable sort, so inside
52 the groups the order is the one of the files.
53 """
54 positions: list[int] = [i for i, item in enumerate(items) if _is_wallet_test(item)]
55 if not positions:
56 return
57 wallet_items: list[pytest.Item] = [items[i] for i in positions]
58 reordered: list[pytest.Item] = sorted(
59 wallet_items,
60 key=lambda item: (_wallet_type_rank(item), 0 if item.nodeid.startswith(_SEND_TESTS) else 1),
61 )
62 for position, item in zip(positions, reordered):
63 items[position] = item