pytest-dev / pytest-cov

Coverage plugin for pytest.
MIT License
1.76k stars 211 forks source link

billiard.Pool support (like multiprocessing.Pool) #380

Open graingert opened 4 years ago

graingert commented 4 years ago
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 commented 4 years ago

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 commented 4 years ago

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()
ionelmc commented 4 years ago

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.

graingert commented 4 years ago

It's not a celery internal