Add autouse fixture to patch CliRunner.invoke with default ctx.obj
Some checks failed
Coverage Phase 1 (70% Target) / test-coverage-70 (push) Has been cancelled
Coverage Phase 2 (85% Target) / test-coverage-85 (push) Has been cancelled
Cross-Node Transaction Testing / transaction-test (push) Has been cancelled
Deploy to Testnet / deploy-testnet (push) Has been cancelled
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled

This commit is contained in:
aitbc
2026-05-27 11:07:52 +02:00
parent 403cbbb70a
commit a21e6ab62b

View File

@@ -64,23 +64,24 @@ import pytest
from click.testing import CliRunner
@pytest.fixture
def cli_runner():
"""CLI runner with mock context object for isolated testing"""
runner = CliRunner()
return runner
@pytest.fixture(autouse=True)
def mock_ctx_obj(monkeypatch):
"""Auto-use fixture that patches CliRunner.invoke to set ctx.obj"""
original_invoke = CliRunner.invoke
@pytest.fixture
def ctx_obj():
"""Mock Click context object for CLI tests"""
return {
def patched_invoke(self, cli, args, **kwargs):
# Ensure obj is set with default context values
if 'obj' not in kwargs or kwargs['obj'] is None:
kwargs['obj'] = {
'output': 'table',
'url': None,
'api_key': None,
'verbose': 0,
'debug': False
}
return original_invoke(self, cli, args, **kwargs)
monkeypatch.setattr(CliRunner, 'invoke', patched_invoke)
@pytest.fixture(scope="session")