[py-dev] pytest-cov measuring multiple subprocesses? (+notes)

meme dough memedough at gmail.com
Thu Aug 5 12:51:42 CEST 2010


Hi,

> i am using pytest-cov for a project where I start multiple subprocesses.
> I am wondering how to best do this, here is the scenario:
>
>    def test_functional():
>        popen1 = subprocess.Popen(...) # new python process
>        popen2 = subprocess.Popen(...) # new python process
>        popen1.terminate()
>        popen2.wait()
>
>
> and now i want pytest-cov to show me the coverage.
> What do i need to do?  Should it "just" work with this:
>
>    py.test --cov=mypkg
>
> ?

Yes, it should just work provided that the subprocesses are python (as
you state above) that have pytest-cov / cov-core installed.  Only
other thing is that it site initialisation as normal and env inherited
as normal.

Those sub processes detect env var and start coverage.  Sub processes
finish and write coverage file (specific per process), then master
py.test finish and combine and report.

> An unrelated note: the py.test distributed coverage-reporting feature
> ("DistMaster" etc.) is living with cov_core.py IISIC. Is this actually re-usable
> from nosetests?  If not it would probably make more sense to have this code in
> pytest-cov for it to be easier to modify and maintain, no?

I liked having all the cov controllers together, but it is possible to move.

> another unrelated note: i like plugins to not cause import overhead if
> their functionality is not actually used.  What about importing cov_core
> only when coverage is actually active?
> :)

Yes this is good way.

:)



More information about the Pytest-dev mailing list