From cbabdf4210313f934ae90d9a853834d9494b3ad5 Mon Sep 17 00:00:00 2001 From: Alessio Bogon Date: Fri, 1 Oct 2021 20:07:43 +0200 Subject: [PATCH] Add configuration to collect types from pytest runs --- tests/conftest.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index d5f6c4f..2d9270a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,3 +20,30 @@ def pytest_generate_tests(metafunc): "pytest_params", parametrizations, ) + + +# TODO: Remove these before merge +def pytest_collection_finish(session): + """Handle the pytest collection finish hook: configure pyannotate. + Explicitly delay importing `collect_types` until all tests have + been collected. This gives gevent a chance to monkey patch the + world before importing pyannotate. + """ + from pyannotate_runtime import collect_types + + collect_types.init_types_collection() + + +@pytest.fixture(autouse=True) +def collect_types_fixture(): + from pyannotate_runtime import collect_types + + collect_types.start() + yield + collect_types.stop() + + +def pytest_sessionfinish(session, exitstatus): + from pyannotate_runtime import collect_types + + collect_types.dump_stats("type_info.json")