Closed starhel closed 8 months ago
Pytest is unaware of multiprocessing
You need to add a passover handler yourself
I am curious whether it is feasible to support multiprocessing in caplog without resorting to hacks, and I am open to preparing a PR with your guidance.
Not sure if it would be possible to implement this in a general manner, as it would require some form of hooking into the subprocess spawning behavior to capture and transfer the captured logging output....
If multiprocessing had some form of way to enable this automatically, I could see we adding support for it to pytest, but a more complicated implementation is probably out of scope for the pytest core. Perhaps a plugin could be a good fit.
I'm closing this for now, but feel free to follow up with more questions.
You need to add a passover handler yourself
Anyone have an example or a link to more info?
found more info: https://github.com/pytest-dev/pytest/issues/3037
A detailed description of the bug or problem
Capturing logs from spawned processes is not working - all calls to logging are missing in
caplog.records
and terminal output (live logs are printed correctly withlog_cli=1
).pip list
and system versionSystem version:
Ubuntu 22.04.3 LTS
Minimal example
Workaround
It's possible to add a workaround to this case when you know which logger you need to hack.
As this workaround works correctly in my tests, I'm aware that it may not working correctly in some scenarios:
pytest-xdist
(probably, never tested)As this example is just simple reproduction, I encountered this issue while implementing tests for code based on luigi framework, where certain code segments are executed in child processes. I am curious whether it is feasible to support multiprocessing in caplog without resorting to hacks, and I am open to preparing a PR with your guidance.