vdirsyncer/tests/conftest.py
Hugo Osvaldo Barrera 1a1f6f0788 Initial async support
Add asyncio to the storage backends and most of the codebase. A lot of
it merely uses asyncio APIs, but still doesn't actually run several
things concurrently internally. Further improvements will be added on
top of these changes

Thanks to  Thomas Grainger (@graingert) for a few useful pointers
related to asyncio.
2021-06-26 13:40:35 +02:00

70 lines
1.4 KiB
Python

"""
General-purpose fixtures for vdirsyncer's testsuite.
"""
import logging
import os
import aiohttp
import click_log
import pytest
from hypothesis import HealthCheck
from hypothesis import settings
from hypothesis import Verbosity
@pytest.fixture(autouse=True)
def setup_logging():
click_log.basic_config("vdirsyncer").setLevel(logging.DEBUG)
try:
import pytest_benchmark
except ImportError:
@pytest.fixture
def benchmark():
return lambda x: x()
else:
del pytest_benchmark
settings.register_profile(
"ci",
settings(
max_examples=1000,
verbosity=Verbosity.verbose,
suppress_health_check=[HealthCheck.too_slow],
),
)
settings.register_profile(
"deterministic",
settings(
derandomize=True,
suppress_health_check=HealthCheck.all(),
),
)
settings.register_profile("dev", settings(suppress_health_check=[HealthCheck.too_slow]))
if os.environ.get("DETERMINISTIC_TESTS", "false").lower() == "true":
settings.load_profile("deterministic")
elif os.environ.get("CI", "false").lower() == "true":
settings.load_profile("ci")
else:
settings.load_profile("dev")
@pytest.fixture
async def aio_session(event_loop):
async with aiohttp.ClientSession() as session:
yield session
@pytest.fixture
async def aio_connector(event_loop):
conn = aiohttp.TCPConnector(limit_per_host=16)
try:
yield conn
finally:
await conn.close()