Root cause: unittest.mock.patch with new_callable=AsyncMock fails in full-suite context due to asyncio event loop state from earlier tests. Fix: use direct module dict patching (gb_mod.run_blocking = AsyncMock()) instead of patch() context manager. This bypasses the mock machinery interaction with inherited event loop state. Also add conftest.py in tests/services/git/ with event_loop fixture for per-function isolation. Result: 2602 passed, 0 failed, 3 skipped, 1 xpassed
28 lines
841 B
Python
28 lines
841 B
Python
"""conftest.py for tests/services/git/
|
|
|
|
When `test_git_base.py` async tests run in the full suite after other
|
|
modules that modify the asyncio event loop, AsyncMock and patch-based
|
|
mocks for async functions may not work correctly.
|
|
|
|
This conftest provides a fixture that forces a fresh asyncio event loop
|
|
per test function, avoiding cross-test contamination.
|
|
"""
|
|
|
|
import asyncio
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def event_loop():
|
|
"""Create a fresh event loop for each test function.
|
|
|
|
Overrides the default pytest-asyncio event_loop fixture to ensure
|
|
that async git_base tests are isolated from event loop state left
|
|
by other test modules in the full suite.
|
|
"""
|
|
policy = asyncio.get_event_loop_policy()
|
|
loop = policy.new_event_loop()
|
|
asyncio.set_event_loop(loop)
|
|
yield loop
|
|
loop.close()
|