conftest.py 1010 B

123456789101112131415161718192021222324252627282930
  1. # Configuration for pytest to automatically collect types.
  2. # Thanks to Guilherme Salgado.
  3. import pytest
  4. try:
  5. import pyannotate_runtime
  6. PYANOTATE_PRESENT = True
  7. except ImportError:
  8. PYANOTATE_PRESENT = False
  9. if PYANOTATE_PRESENT:
  10. def pytest_collection_finish(session):
  11. """Handle the pytest collection finish hook: configure pyannotate.
  12. Explicitly delay importing `collect_types` until all tests have
  13. been collected. This gives gevent a chance to monkey patch the
  14. world before importing pyannotate.
  15. """
  16. from pyannotate_runtime import collect_types
  17. collect_types.init_types_collection()
  18. @pytest.fixture(autouse=True)
  19. def collect_types_fixture():
  20. from pyannotate_runtime import collect_types
  21. collect_types.resume()
  22. yield
  23. collect_types.pause()
  24. def pytest_sessionfinish(session, exitstatus):
  25. from pyannotate_runtime import collect_types
  26. collect_types.dump_stats("type_info.json")