Skip to content

test(integration): add real-NATS pytest fixture (#173)#519

Merged
mvillmow merged 1 commit into
mainfrom
173-real-nats-pytest-fixture
May 14, 2026
Merged

test(integration): add real-NATS pytest fixture (#173)#519
mvillmow merged 1 commit into
mainfrom
173-real-nats-pytest-fixture

Conversation

@mvillmow
Copy link
Copy Markdown
Contributor

Summary

  • Adds a session-scoped nats_url pytest fixture that starts a real nats-server process with JetStream on an ephemeral port (mirrors ProjectScylla's tests/integration/nats/conftest.py).
  • Adds one integration test test_subscribe_loop_records_published_events that runs the jetstream-consumer subscribe_loop against the live server, publishes synthetic hi.tasks.completed / hi.agents.created events, and asserts the rendered /metrics output reflects counts, the _connected=1 gauge, and the computed task-latency value.
  • Registers integration and requires_nats pytest markers in pyproject.toml so --strict-markers accepts them. The requires_nats marker mirrors Charybdis's REQUIRES_NATS ctest gate.
  • The test module is skipped when either nats-server is not on PATH or nats-py is not installed, so existing CI (which lacks both) stays green and the test only fires on machines provisioned for integration runs.

Closes #173

Test plan

  • pytest tests/ passes locally with 320 tests + 1 new integration test, exporter coverage 99.40%.
  • env -i PATH=/usr/bin:/bin python3 -m pytest tests/integration/ reports 1 skipped when nats-server is removed from PATH.
  • ruff check exporter/ tests/ clean.
  • CI: validate, unit-tests, test, lint, security all green on the PR.

Follow-up from #4.

Co-authored-by: Claude Opus 4.7 (1M context) noreply@anthropic.com

Adds a session-scoped pytest fixture that spins up a real `nats-server`
process with JetStream enabled on an ephemeral port, plus one integration
test that exercises `jetstream-consumer` end-to-end: publish synthetic
hi.tasks.completed / hi.agents.created events, run subscribe_loop in a
background thread, and assert that _render_metrics() reflects the
consumed events and computed task latency.

Mirrors ProjectScylla's tests/integration/nats/conftest.py shape and
Charybdis's REQUIRES_NATS ctest gate: the module is skipped when either
`nats-server` is not on PATH or `nats-py` is not installed, so existing
CI (which lacks both) stays green and the test only fires on machines
provisioned for integration runs.

Registers `integration` and `requires_nats` pytest markers in
pyproject.toml so `--strict-markers` accepts them.

Closes #173

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mvillmow mvillmow enabled auto-merge (squash) May 14, 2026 03:02
@mvillmow mvillmow merged commit 4f04302 into main May 14, 2026
20 checks passed
@mvillmow mvillmow deleted the 173-real-nats-pytest-fixture branch May 14, 2026 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add integration test using a real NATS server via pytest fixture

1 participant