Enable multiprocess coverage tracking with coverage.process_startup()#1122
Enable multiprocess coverage tracking with coverage.process_startup()#1122
Conversation
Co-authored-by: vringar <13276717+vringar@users.noreply.github.com>
Co-authored-by: vringar <13276717+vringar@users.noreply.github.com>
|
@copilot The current approach ( The core issue: OpenWPM's worker processes (
What you need to do instead: Use
@pytest.fixture(scope="session", autouse=True)
def enable_subprocess_coverage():
"""Enable coverage collection in child processes when running under coverage."""
try:
import coverage
# Only set this if we're actually measuring coverage
if coverage.Coverage.current() is not None:
os.environ["COVERAGE_PROCESS_START"] = str(
Path(__file__).parent.parent / "pyproject.toml"
)
except ImportError:
pass
The key files to modify:
|
|
@copilot One more thing: before implementing the above, investigate whether Check if there's anything in |
Co-authored-by: vringar <13276717+vringar@users.noreply.github.com>
Co-authored-by: vringar <13276717+vringar@users.noreply.github.com>
Implemented all the requested changes:
|
Co-authored-by: vringar <13276717+vringar@users.noreply.github.com>
Investigated the issue. Added
Commit 74a8843 |
Coverage metrics were missing code executed in child processes. OpenWPM spawns worker processes (BrowserManager, StorageController) using the
multiprocesslibrary that were not being tracked.Problem
OpenWPM uses the
multiprocesslibrary (a fork of stdlibmultiprocessing) for worker processes. Standard coverage configuration approaches don't work because:patch = ["subprocess"]only instrumentssubprocess.Popen/os.system(), which OpenWPM doesn't use for workersconcurrency = ["multiprocessing"]monkeypatches stdlibmultiprocessing, not themultiprocessforkSolution
Implemented manual coverage initialization in child processes using
coverage.process_startup():Changes Made
Modified
openwpm/utilities/multiprocess_utils.py:coverage.process_startup()call at the beginning ofProcess.run()COVERAGE_PROCESS_STARTenvironment variable check so it only activates during test runsModified
openwpm/browser_manager.py:Processfromopenwpm.utilities.multiprocess_utilswrapper instead of directly frommultiprocesslibrarycoverage.process_startup()directly inBrowserManager.run()since it overrides the parent'srun()method without callingsuper().run(), which would bypass the wrapper's coverage initializationAdded pytest fixture in
test/conftest.py:enable_subprocess_coverage()COVERAGE_PROCESS_STARTto point topyproject.tomlwhen tests run under coverageConfiguration in
pyproject.toml:concurrency = ["multiprocessing"],parallel = true, andsigterm = truepatch = ["subprocess"]This enables proper coverage collection across all multiprocess worker processes during test runs, following the approach documented in coverage.py's subprocess measurement guide. Both process patterns are now covered:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.