Skip to content

Run integration tests in a single shared session#126

Closed
jackwildman wants to merge 1 commit intomainfrom
integration-tests-one-session
Closed

Run integration tests in a single shared session#126
jackwildman wants to merge 1 commit intomainfrom
integration-tests-one-session

Conversation

@jackwildman
Copy link
Copy Markdown
Contributor

Summary

  • Add a session-scoped pytest fixture in conftest.py that creates one shared everyrow session for all integration tests
  • Update all 26 integration tests to use the shared session fixture instead of creating their own
  • Add asyncio_default_fixture_loop_scope = "session" to pytest config for proper async fixture support

Test plan

  • Run integration tests with pytest -m integration and verify only one session is created
  • Check everyrow dashboard to confirm single session with timestamp name

🤖 Generated with Claude Code

Add a session-scoped pytest fixture that creates one everyrow session
for all integration tests to share, reducing the number of sessions
created during test runs. Each test now receives and uses this shared
session instead of creating its own.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jackwildman jackwildman requested a review from hnykda February 10, 2026 15:42
Comment on lines +22 to +28
@pytest_asyncio.fixture(scope="session")
async def session() -> AsyncGenerator[Session, None]:
"""Create a single shared session for all integration tests."""
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
async with create_session(name=f"integration-tests-{timestamp}") as sess:
yield sess

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The session-scoped async fixture runs in a different event loop than the tests, which will cause runtime errors because asyncio objects are not cross-loop compatible.
Severity: CRITICAL

Suggested Fix

Add @pytest.mark.asyncio(loop_scope="session") to all integration test markers. Alternatively, implement a pytest_collection_modifyitems hook to automatically apply this marker to all async tests, ensuring they share the same event loop as the session-scoped fixture.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: tests/integration/conftest.py#L22-L28

Potential issue: The `pyproject.toml` configuration `asyncio_default_fixture_loop_scope
= "session"` only applies to fixtures, not the tests themselves. Since the integration
tests are not explicitly marked with `@pytest.mark.asyncio(loop_scope="session")`, they
will default to function-scoped event loops. This creates a mismatch where the shared
`Session` object, created in the session-scoped loop, is used across different
function-scoped loops. This is not permitted by asyncio and will lead to runtime errors
like `RuntimeError: Event loop is closed` when the tests attempt to use the async
client.

Did we get this right? 👍 / 👎 to inform future reviews.

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.

2 participants