Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix coverage report for application with multiprocessing #601

Merged
merged 3 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*$py.class
*.orig
example.cfg
.coverage
.coverage*
.idea
nosetests.xml
xunit.xml
Expand Down
5 changes: 3 additions & 2 deletions nose2/plugins/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(self):
self.covConfig = (
self.config.as_str("coverage-config", "").strip() or ".coveragerc"
)
self.covCombine = self.config.as_bool("coverage-combine", False)

group = self.session.pluginargs
group.add_argument(
Expand Down Expand Up @@ -125,8 +126,8 @@ def beforeSummaryReport(self, event):
# requesting a better fix in nedbat/coveragepy#34
self.covController.save()

if self._mpmode:
self.covController.combine(strict=True)
if self.covCombine or self._mpmode:
self.covController.combine(strict=self._mpmode)

percent_coverage = None

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
concurrency = multiprocessing
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from multiprocessing import Process


def method2():
return


def method():
p = Process(method2())
p.start()
p.join()
return True
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[coverage]
always-on = True
coverage = lib
coverage-config = .coveragerc
coverage-combine = True
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import unittest

from lib.mod1 import method


class TestLib(unittest.TestCase):
def test1(self):
self.assertEqual(method(), True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
concurrency = multiprocessing
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from multiprocessing import Process


def method2():
return


def method():
p = Process(method2())
p.start()
p.join()
return True
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[coverage]
always-on = True
coverage = lib
coverage-config = .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import unittest

from lib.mod1 import method


class TestLib(unittest.TestCase):
def test1(self):
self.assertEqual(method(), True)
10 changes: 10 additions & 0 deletions nose2/tests/functional/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,13 @@ def test_run_coverage_fail_under2(self):
total_stats=TOTAL_STATS,
assert_exit_status=1,
)

def test_run_coverage_with_combine(self):
"""Check coverage with combine"""
proc = self.runIn("scenario/coverage_multiprocessing_with_combine", "-v")
self.assertProcOutputPattern(proc, "lib", r"\s+12\s+0\s+100%")

def test_run_coverage_without_combine(self):
"""Check coverage without combine"""
proc = self.runIn("scenario/coverage_multiprocessing_without_combine", "-v")
self.assertProcOutputPattern(proc, "lib", r"\s+8\s+3\s+62%")
Loading