openai-agents-python/tests/realtime
2026-10-26 22:07:02 +00:00
..
__init__.py [6/n] RealtimeSession + events (#1073) 2025-07-11 15:13:42 -04:00
README.md test: organize Realtime session tests by responsibility (#4879) 2026-09-05 18:13:16 +09:00
session_test_support.py fix(core): scope function tool approvals to their owning agent (#5144) 2026-09-25 14:21:25 -07:00
test_agent.py fix: await async callable-object dynamic instructions (#3942) 2026-07-24 22:01:19 +00:00
test_app_server_debug.py fix(examples): keep realtime debug error summaries payload-free (#5200) 2026-09-27 13:21:12 -07:00
test_app_server_security.py fix(examples): restrict the Realtime demo to local bounded sessions (#5111) 2026-09-20 17:31:29 +09:00
test_audio_formats_unit.py fix(realtime): handle non-finite audio rates (#4419) 2026-08-14 21:54:43 +00:00
test_conversion_helpers.py feat: update default realtime model to gpt-realtime-2.1 (#3740) 2026-07-07 09:23:20 +09:00
test_ga_session_update_normalization.py feat: #1614 gpt-realtime migration (Realtime API GA) (#1646) 2025-09-11 13:56:20 -04:00
test_item_parsing.py fix(realtime): preserve item status on retrieved conversation items (#4598) 2026-08-25 03:04:10 +00:00
test_model_events.py fix(realtime): end iteration after clean server close (#4461) 2026-08-16 18:21:35 +09:00
test_openai_realtime.py fix(realtime): honor explicit interruption with automatic VAD (#5427) 2026-10-26 22:07:02 +00:00
test_openai_realtime_conversions.py feat(realtime): track response usage in session context (#3812) 2026-07-13 07:42:49 +09:00
test_openai_realtime_sip_model.py feat: #1760 Add SIP support for realtime agent runner (#1993) 2025-10-30 07:35:58 +09:00
test_playback_tracker.py fix(realtime): compute G.711 audio length for typed and mapping format spellings (#4292) 2026-08-08 09:08:48 +09:00
test_playback_tracker_manual_unit.py fix: #2009 #2010 Improve PCM duration calculation and handle VAD truncation (#2059) 2026-01-08 15:57:33 +09:00
test_realtime_handoffs.py fix: cancel sibling enablement checks on failure (#4005) 2026-07-29 14:42:30 +09:00
test_realtime_model_settings.py fix: cancel sibling enablement checks on failure (#4005) 2026-07-29 14:42:30 +09:00
test_runner.py feat: add scripted model test utilities (#4362) 2026-08-13 11:20:33 +09:00
test_session.py fix(realtime): honor explicit interruption with automatic VAD (#5427) 2026-10-26 22:07:02 +00:00
test_session_approvals.py fix(core): scope function tool approvals to their owning agent (#5144) 2026-09-25 14:21:25 -07:00
test_session_close_iteration.py fix(realtime): end event iteration when session close starts (#5172) 2026-09-25 08:54:00 -07:00
test_session_exceptions.py feat: add scripted model test utilities (#4362) 2026-08-13 11:20:33 +09:00
test_session_guardrails.py test: organize Realtime session tests by responsibility (#4879) 2026-09-05 18:13:16 +09:00
test_session_history.py test: organize Realtime session tests by responsibility (#4879) 2026-09-05 18:13:16 +09:00
test_session_payload_and_formats.py Fix falsy optional reference handling (#4305) 2026-08-08 17:55:23 +09:00
test_session_tool_error_events.py fix(realtime): redact exception details from Realtime tool error events (#5132) 2026-09-21 14:31:31 +09:00
test_session_tool_output_guardrails.py fix(realtime): enforce Realtime tool output guardrails (#5127) 2026-09-21 11:56:45 +09:00
test_session_tool_outputs.py test: organize Realtime session tests by responsibility (#4879) 2026-09-05 18:13:16 +09:00
test_testing.py feat: add scripted model test utilities (#4362) 2026-08-13 11:20:33 +09:00
test_tracing.py feat: update default realtime model to gpt-realtime-2.1 (#3740) 2026-07-07 09:23:20 +09:00
test_twilio_example.py docs: authenticate Twilio streams and clean up sessions (#5110) 2026-09-21 06:45:32 +09:00
test_twilio_sip_server.py docs(realtime): make Twilio SIP transcript logging opt-in (#5134) 2026-09-21 14:36:41 +09:00
test_websocket_message_size.py fix(realtime): bound incoming WebSocket message size by default (#5102) 2026-09-20 16:57:17 +09:00

Realtime session test groups

Run a behavior group directly from the repository root:

uv run pytest tests/realtime/test_session_approvals.py
uv run pytest tests/realtime/test_session_tool_outputs.py
uv run pytest tests/realtime/test_session_guardrails.py
uv run pytest tests/realtime/test_session_history.py
uv run pytest tests/realtime

File selection avoids importing or collecting the other session groups. It is a navigation and test-selection boundary; splitting files does not by itself imply a faster full suite. Existing -k filters and class/function selection still work within each new file.

Module Responsibility
test_session.py Session entry/exit, event forwarding, tool dispatch and timeouts, handoffs, model settings, and update-agent behavior.
test_session_approvals.py Function-tool approval requests, sticky decisions, rejection formatting, and pre/post-approval input guardrails.
test_session_tool_outputs.py Function-tool output serialization, send failures, and retries without repeating execution.
test_session_guardrails.py Response-scoped output guardrails, feedback ordering, and audio interruption.
test_session_history.py Item insertion/update/deletion, transcript merging, and transcript preservation.

Fixture and helper ownership

session_test_support.py owns the existing _DummyModel, RecordingRealtimeModel, and shared function-tool helpers. Each model instance remains constructed per test. The session modules explicitly bind only the fixtures they use from that support module: mock_agent, mock_model, and, for tool-related modules, mock_function_tool. These fixtures retain pytest's default function scope and are not autouse. There is no Realtime-wide conftest.py introducing them to unrelated test modules.

TestGuardrailFunctionality keeps its function-scoped triggered_guardrail and safe_guardrail fixtures and _wait_for_guardrail_tasks helper. Specialized blocking/failing model subclasses stay inside their original test functions. _FakeAudio belongs to history tests; TestToolCallExecution.ToolResult belongs to output serialization tests. The original file retains its connection/enablement/traceback helpers and mock_handoff fixture. Repository-wide tracing, fake API credentials, and cleanup remain owned by tests/conftest.py.

Relocation map

The source for every relocation below is test_session.py at 3e0e89374f629c974929054e56e823a43c91a013. Class names, function names, and every bracketed parameter ID are unchanged. Replace only the file prefix of an old pytest node ID. Any node not listed below remains in test_session.py, including lifecycle tests that exercise history suppression after close or background guardrail cleanup.

For example:

tests/realtime/test_session.py::TestToolCallExecution::test_serialize_tool_output_edge_cases[dataclass]
    -> tests/realtime/test_session_tool_outputs.py::TestToolCallExecution::test_serialize_tool_output_edge_cases[dataclass]

Whole classes move as follows:

Original class Destination
TestHistoryManagement test_session_history.py
TestTranscriptPreservation test_session_history.py
TestGuardrailFunctionality test_session_guardrails.py

The remaining relocations below retain their original containing class, where shown. All other methods of the partial classes remain in test_session.py.

test_session_approvals.py

  • TestToolCallExecution::test_approval_resume_uses_pending_initial_settings_dispatch_snapshot
  • TestToolCallExecution::test_function_tool_needs_approval_emits_event
  • TestToolCallExecution::test_callable_function_approval_fails_closed_for_invalid_arguments
  • TestToolCallExecution::test_callable_function_approval_receives_valid_object_arguments
  • TestToolCallExecution::test_tool_input_guardrail_rejects_before_realtime_function_execution
  • TestToolCallExecution::test_realtime_pending_approval_skips_tool_input_guardrails_by_default
  • TestToolCallExecution::test_realtime_pre_approval_tool_input_guardrail_rejects_pending_approval
  • TestToolCallExecution::test_realtime_pre_approval_tool_input_guardrails_rerun_after_approval
  • TestToolCallExecution::test_duplicate_pending_approval_call_id_is_ignored_and_approval_runs_once
  • TestToolCallExecution::test_approve_pending_tool_call_runs_tool
  • TestToolCallExecution::test_async_approve_pending_tool_call_reserves_call_id_before_task_runs
  • TestToolCallExecution::test_always_approve_namespaced_tool_call_does_not_approve_bare_tool
  • TestToolCallExecution::test_reject_pending_tool_call_sends_rejection_output
  • TestToolCallExecution::test_reject_pending_tool_call_reserves_call_id_before_sending
  • TestToolCallExecution::test_reject_pending_tool_call_uses_run_level_formatter
  • TestToolCallExecution::test_rejection_formatter_error_is_redacted
  • TestToolCallExecution::test_cancelled_rejection_formatter_leaves_invocation_executed
  • TestToolCallExecution::test_reject_pending_tool_call_prefers_explicit_message
  • TestToolCallExecution::test_always_reject_namespaced_tool_call_reuses_explicit_message
  • TestToolCallExecution::test_sticky_rejection_does_not_bind_duplicate_call_id_payload
  • TestToolCallExecution::test_sticky_rejection_skips_dynamic_approval_checker
  • TestToolCallExecution::test_sticky_rejection_wins_while_dynamic_approval_checker_is_pending
  • TestToolCallExecution::test_sticky_decision_wins_while_rejecting_pre_approval_guardrail_is_pending

test_session_tool_outputs.py

  • TestToolCallExecution::test_approved_function_tool_failure_replay_does_not_rerun
  • TestToolCallExecution::test_function_tool_send_failure_retries_cached_output_without_rerun
  • TestToolCallExecution::test_tool_end_cancellation_after_output_send_does_not_resend
  • TestToolCallExecution::test_async_function_tool_send_failure_retries_cached_output_without_rerun
  • TestToolCallExecution::test_pending_function_output_rejects_handoff_role_reuse
  • TestToolCallExecution::test_async_exact_function_retry_after_serialization_failure_does_not_repeat_callback
  • TestToolCallExecution::test_tool_result_conversion_to_string
  • TestToolCallExecution::test_tool_result_conversion_serializes_pydantic_models
  • TestToolCallExecution::test_serialize_tool_output_ignores_non_pydantic_model_dump_objects
  • TestToolCallExecution::test_serialize_tool_output_falls_back_when_pydantic_json_dump_fails
  • TestToolCallExecution::test_serialize_tool_output_returns_string_when_pydantic_dump_fails
  • TestToolCallExecution::test_serialize_tool_output_returns_string_when_dataclass_asdict_fails
  • TestToolCallExecution::test_serialize_tool_output_edge_cases

test_session_history.py

  • test_transcription_completed_adds_new_user_item
  • test_item_updated_merge_exception_path_logs_error
  • TestEventHandling::test_transcription_completed_event_updates_history
  • TestEventHandling::test_item_updated_event_adds_new_item
  • TestEventHandling::test_item_updated_event_updates_existing_item
  • TestEventHandling::test_item_updated_event_completes_tool_call
  • TestEventHandling::test_item_deleted_event_removes_item

The relocation preserves all 198 collected session cases: 95 in test_session.py, 30 in test_session_approvals.py, 22 in test_session_tool_outputs.py, 29 in test_session_guardrails.py, 22 in test_session_history.py. These counts describe the relocation baseline, not a requirement for future test additions.