Skip to content

Commit

Permalink
Allow Coverage to detect code running in subprocesses
Browse files Browse the repository at this point in the history
  • Loading branch information
noah-weingarden committed Nov 26, 2023
1 parent c147a87 commit b85f9c7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
concurrency = thread,multiprocessing
parallel = true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ build/
/.tox/
/.coverage*
*,cover
# Make an exception for .coveragerc, which should be checked into version control.
!.coveragerc

# Text editors and IDEs
*~
Expand Down
10 changes: 9 additions & 1 deletion madoop/mapreduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,16 @@ def group_stage(input_dir, output_dir, num_reducers):
path.unlink()

# Sort output files
with multiprocessing.Pool(processes=multiprocessing.cpu_count()) as pool:
try:
# Don't use a with statement here, because Coverage won't be able to
# detect code running in a subprocess if we do.
# https://pytest-cov.readthedocs.io/en/latest/subprocess-support.html
# pylint: disable=consider-using-with
pool = multiprocessing.Pool(processes=multiprocessing.cpu_count())
pool.map(sort_file, sorted(output_dir.iterdir()))
finally:
pool.close()
pool.join()

log_output_key_stats(output_keys_stats, output_dir)

Expand Down

0 comments on commit b85f9c7

Please sign in to comment.