Skip to content

Commit 3de648a

Browse files
authored
Merge pull request #605 from nose-devs/add-fix-for-subproc-tests
Add a fix for nose2's own subprocess tests (on top of #601)
2 parents 0610f47 + d838581 commit 3de648a

File tree

15 files changed

+81
-14
lines changed

15 files changed

+81
-14
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*$py.class
1010
*.orig
1111
example.cfg
12-
.coverage
12+
.coverage*
1313
.idea
1414
nosetests.xml
1515
xunit.xml

nose2/plugins/coverage.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def __init__(self):
5555
self.covConfig = (
5656
self.config.as_str("coverage-config", "").strip() or ".coveragerc"
5757
)
58+
self.covCombine = self.config.as_bool("coverage-combine", False)
5859

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

128-
if self._mpmode:
129-
self.covController.combine(strict=True)
129+
if self.covCombine or self._mpmode:
130+
self.covController.combine(strict=self._mpmode)
130131

131132
percent_coverage = None
132133

nose2/tests/_common.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ def assertTestRunOutputMatches(self, proc, stdout=None, stderr=None):
8181
if stderr:
8282
self.assertRegex(util.safe_decode(cmd_stderr), stderr)
8383

84+
def runInProc(self, working_dir, *args, timeout=10):
85+
if not os.path.isabs(working_dir):
86+
working_dir = support_file(working_dir)
87+
88+
proc = subprocess.Popen(
89+
[sys.executable, "-m", "nose2"] + list(args),
90+
stdout=subprocess.PIPE,
91+
stderr=subprocess.PIPE,
92+
cwd=working_dir,
93+
)
94+
proc.wait(timeout=timeout)
95+
return proc
96+
8497
def runIn(self, testdir, *args, **kw):
8598
return run_nose2(*args, cwd=testdir, **kw)
8699

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[run]
2+
concurrency = multiprocessing

nose2/tests/functional/support/scenario/coverage_multiprocessing_with_combine/lib/__init__.py

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from multiprocessing import Process
2+
3+
4+
def method2():
5+
return
6+
7+
8+
def method():
9+
p = Process(target=method2)
10+
p.start()
11+
p.join()
12+
return True
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[coverage]
2+
always-on = True
3+
coverage = lib
4+
coverage-config = .coveragerc
5+
coverage-combine = True
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import unittest
2+
3+
from lib.mod1 import method
4+
5+
6+
class TestLib(unittest.TestCase):
7+
def test1(self):
8+
self.assertEqual(method(), True)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[run]
2+
concurrency = multiprocessing

nose2/tests/functional/support/scenario/coverage_multiprocessing_without_combine/lib/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)