Files
stonks-oracle/tests/integration/conftest_profiling.py
T
Celes Renata b2b8aca7c6
ci/woodpecker/push/woodpecker Pipeline failed
Build and Push / lint-and-test (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.adapters.broker_adapter name:broker-adapter]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.aggregation.worker name:aggregation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.extractor.worker name:extractor]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.ingestion.worker name:ingestion]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.lake_publisher.worker name:lake-publisher]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.parser.worker name:parser]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.recommendation.worker name:recommendation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.scheduler.app name:scheduler]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.api.app:app --host 0.0.0.0 --port 8000 name:query-api]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.risk.app:app --host 0.0.0.0 --port 8000 name:risk]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.symbol_registry.app:app --host 0.0.0.0 --port 8000 name:symbol-registry]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.trading.app:app --host 0.0.0.0 --port 8000 name:trading-engine]) (push) Has been cancelled
Build and Push / build-dashboard (push) Has been cancelled
Build and Push / build-superset (push) Has been cancelled
Build and Push / integration-test (push) Has been cancelled
fix: inttest runner crash and minio bucket-init proxy issue
- Remove --profiling-output arg from runner.yaml (plugin uses default path)
- Inline profiling hooks in root conftest.py with graceful fallback
- Replace mc-based bucket-init with Python urllib (no proxy interference)
- Add explicit ProxyHandler({}) to guarantee no proxy usage in bucket-init
2026-04-19 19:15:20 +00:00

79 lines
2.7 KiB
Python

"""Pytest plugin for integration test profiling.
Adds a ``--profiling-output`` CLI option and hooks into the pytest session
lifecycle to collect endpoint timing data via :class:`EndpointProfiler` and
write a JSON report at the end of the run.
The plugin is automatically loaded by pytest because it lives in the
``tests/integration/`` directory alongside ``conftest.py``. It registers
a session-scoped ``profiler`` fixture that other fixtures (e.g. the
profiled HTTP clients in conftest.py) can depend on.
"""
from __future__ import annotations
import pytest
from tests.integration.profiler import EndpointProfiler
# ---------------------------------------------------------------------------
# CLI option — registered by root conftest.py to ensure availability
# ---------------------------------------------------------------------------
DEFAULT_PROFILING_OUTPUT = "/tmp/profiling-report.json"
# ---------------------------------------------------------------------------
# Session-scoped profiler instance (shared across all tests)
# ---------------------------------------------------------------------------
# Module-level reference so the session hooks can access it without fixtures.
_profiler: EndpointProfiler | None = None
@pytest.fixture(scope="session")
def profiler() -> EndpointProfiler:
"""Session-scoped :class:`EndpointProfiler` instance.
Collects timing data across all integration tests. The summary is
printed and written to disk by the ``pytest_sessionfinish`` and
``pytest_terminal_summary`` hooks below.
"""
global _profiler # noqa: PLW0603
_profiler = EndpointProfiler()
return _profiler
# ---------------------------------------------------------------------------
# Session hooks — write report + print summary
# ---------------------------------------------------------------------------
def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None:
"""Write the profiling JSON report after all tests complete."""
if _profiler is None:
return
output_path = session.config.getoption("profiling_output", DEFAULT_PROFILING_OUTPUT)
try:
_profiler.write_json(output_path)
except OSError:
# Best-effort — don't fail the session if we can't write the report
pass
def pytest_terminal_summary(
terminalreporter: pytest.TerminalReporter,
exitstatus: int,
config: pytest.Config,
) -> None:
"""Print the profiling summary table at the end of the test session."""
if _profiler is None:
return
output_path = config.getoption("profiling_output", DEFAULT_PROFILING_OUTPUT)
terminalreporter.section("Profiling Summary")
_profiler.print_summary()
terminalreporter.write_line(f"JSON report written to: {output_path}")