Skip to content

Commit ff41c1d

Browse files
Luca CandelaLuca Candela
authored andcommitted
Skip asyncio tests when pytest-asyncio missing
1 parent bef62ee commit ff41c1d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
pytest_plugins = ['tests.integration.shared.fixtures_services']
1515

16+
try: # pragma: no cover - optional dependency guard
17+
import pytest_asyncio # type: ignore[unused-import]
18+
HAS_PYTEST_ASYNCIO = True
19+
except ImportError: # pragma: no cover - plugin unavailable
20+
HAS_PYTEST_ASYNCIO = False
21+
1622
# This code adds the project root directory to the Python path, allowing imports to work correctly when running tests.
1723
# Without this file, you might encounter ModuleNotFoundError when trying to import modules from your project, especially when running tests.
1824
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__))))
@@ -49,6 +55,14 @@ def mock_embedder():
4955
return make_mock_embedder()
5056

5157

58+
def pytest_collection_modifyitems(config, items): # pragma: no cover - discovery guard
59+
if not HAS_PYTEST_ASYNCIO:
60+
skip_asyncio = pytest.mark.skip(reason='pytest-asyncio is not installed in this environment')
61+
for item in items:
62+
if 'asyncio' in item.keywords:
63+
item.add_marker(skip_asyncio)
64+
65+
5266
@pytest.fixture(scope='session', autouse=True)
5367
def _patch_aiohttp_client_session():
5468
yield

0 commit comments

Comments
 (0)