Run integration tests in a single shared session#126
Closed
jackwildman wants to merge 1 commit intomainfrom
Closed
Run integration tests in a single shared session#126jackwildman wants to merge 1 commit intomainfrom
jackwildman wants to merge 1 commit intomainfrom
Conversation
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>
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 | ||
|
|
There was a problem hiding this comment.
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.
hnykda
approved these changes
Feb 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
conftest.pythat creates one shared everyrow session for all integration testsasyncio_default_fixture_loop_scope = "session"to pytest config for proper async fixture supportTest plan
pytest -m integrationand verify only one session is created🤖 Generated with Claude Code