pytest-cov icon indicating copy to clipboard operation
pytest-cov copied to clipboard

billiard.Pool support (like multiprocessing.Pool)

Open graingert opened this issue 5 years ago • 4 comments

platform linux2 -- Python 2.7.14, pytest-4.6.5, py-1.8.0, pluggy-0.12.0
plugins: xdist-1.29.0, cov-2.8.1, lazy-fixture-0.5.2, randomly-1.2.3, forked-1.0.2, instafail-0.4.1.post0
coverage==5.0.2
def _smoke_test_in_process():
    assert str(3) == "3"


def test_ham():
    import billiard as multiprocessing

    pool = multiprocessing.Pool(processes=1)
    pool.apply(_smoke_test_in_process)
    pool.join()

and I get a report that assert str(3) == "3" isn't covered

when swapping import billiard as multiprocessing for import multiprocessing I get 100% coverage

graingert avatar Jan 08 '20 17:01 graingert

billiard is a fork of the Python 2.7 multiprocessing package. The multiprocessing package itself is a renamed and updated version of R Oudkerk’s pyprocessing package. This standalone variant draws its fixes/improvements from python-trunk and provides additional bug fixes and improvements.

so it's helpful when testing python3 apps that use Celery, and python2 apps that require a multiprocessing module that actually works

graingert avatar Jan 08 '20 17:01 graingert

as a side note, running

def _initializer():
    from pytest_cov.embed import cleanup_on_sigterm
    cleanup_on_sigterm


def _smoke_test_in_process():
    assert str(3) == "3"


def test_ham():
    import billiard as multiprocessing

    with multiprocessing.Pool(processes=1, initializer=_initializer) as pool:
        pool.apply(_smoke_test_in_process)
    pool.join()

also results in assert str(3) == "3" being missed

I do get 100% coverage when running the _initializer in the _smoke_test_in_process

def _initializer():
    from pytest_cov.embed import cleanup_on_sigterm
    cleanup_on_sigterm


def _smoke_test_in_process():
    _initializer()
    assert str(3) == "3"


def test_ham():
    import billiard as multiprocessing

    with multiprocessing.Pool(processes=1) as pool:
        pool.apply(_smoke_test_in_process)
    pool.join()

graingert avatar Jan 08 '20 17:01 graingert

Well ok but does anyone except celery actually use billiard? I'd rather look at how celery is supported than its internals that no one else uses.

ionelmc avatar Jan 12 '20 19:01 ionelmc

It's not a celery internal

graingert avatar Jan 12 '20 19:01 graingert