conftest.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # (c) Nelen & Schuurmans
  2. import asyncio
  3. import os
  4. import pytest
  5. def pytest_sessionstart(session):
  6. """
  7. Called after the Session object has been created and
  8. before performing collection and entering the run test loop.
  9. """
  10. if os.environ.get("DEBUG") or os.environ.get("DEBUG_WAIT_FOR_CLIENT"):
  11. from clean_python.testing.debugger import setup_debugger
  12. setup_debugger()
  13. @pytest.fixture(scope="session")
  14. def event_loop(request):
  15. """Create an instance of the default event loop per test session.
  16. Async fixtures need the event loop, and so must have the same or narrower scope than
  17. the event_loop fixture. Since we have async session-scoped fixtures, the default
  18. event_loop fixture, which has function scope, cannot be used. See:
  19. https://github.com/pytest-dev/pytest-asyncio#async-fixtures
  20. """
  21. loop = asyncio.get_event_loop_policy().new_event_loop()
  22. yield loop
  23. loop.close()
  24. @pytest.fixture(scope="session")
  25. async def postgres_url():
  26. return os.environ.get("POSTGRES_URL", "postgres:postgres@localhost:5432")