diff --git a/mypy.ini b/mypy.ini --- a/mypy.ini +++ b/mypy.ini @@ -24,6 +24,9 @@ [mypy-django.*] ignore_missing_imports = True +[mypy-multiprocessing.util] +ignore_missing_imports = True + [mypy-pkg_resources.*] ignore_missing_imports = True @@ -33,6 +36,9 @@ [mypy-pytest.*] ignore_missing_imports = True +[mypy-pytest_cov.*] +ignore_missing_imports = True + [mypy-pytest_kafka.*] ignore_missing_imports = True diff --git a/swh/storage/tests/conftest.py b/swh/storage/tests/conftest.py --- a/swh/storage/tests/conftest.py +++ b/swh/storage/tests/conftest.py @@ -5,16 +5,21 @@ import glob import pytest - +import multiprocessing.util from typing import Union -from pytest_postgresql import factories -from pytest_postgresql.janitor import DatabaseJanitor, psycopg2, Version - from os import path, environ from hypothesis import settings from typing import Dict +try: + import pytest_cov.embed +except ImportError: + pytest_cov = None + +from pytest_postgresql import factories +from pytest_postgresql.janitor import DatabaseJanitor, psycopg2, Version + import swh.storage from swh.core.utils import numfile_sortkey as sortkey @@ -54,6 +59,21 @@ settings.register_profile("slow", max_examples=20, deadline=5000) +if pytest_cov is not None: + # pytest_cov + multiprocessing can cause a segmentation fault when starting + # the child process ; so we're + # removing pytest-coverage's hook that runs when a child process starts. + # This means code run in child processes won't be counted in the coverage + # report, but this is not an issue because the only code that runs only in + # child processes is the RPC server. + for (key, value) in multiprocessing.util._afterfork_registry.items(): + if value is pytest_cov.embed.multiprocessing_start: + del multiprocessing.util._afterfork_registry[key] + break + else: + assert False, "missing pytest_cov.embed.multiprocessing_start?" + + @pytest.fixture def swh_storage_backend_config(postgresql_proc, swh_storage_postgresql): yield {