Skip to content

Commit 394921b

Browse files
committed
merging...
2 parents af39229 + 313d5b9 commit 394921b

File tree

6 files changed

+101
-26
lines changed

6 files changed

+101
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.tox/
22
*.egg-info/
33
.coverage
4+
.coverage.*
45
*.pyc

example-tox-project/.coveragerc

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

example-tox-project/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ envlist = cov-init,py27,py34,cov-report
66
usedevelop=True
77
setenv =
88
COVERAGE_FILE = .coverage.{envname}
9-
commands = py.test --cov mylib --cov-report= {posargs}
9+
commands = py.test --cov --cov-report= {posargs}
1010
deps =
1111
../cov-core
1212
pytest

pytest-cov/pytest_cov.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ class CoverageError(Exception):
1515
def pytest_addoption(parser):
1616
"""Add options to control coverage."""
1717

18-
group = parser.getgroup('coverage reporting with distributed testing '
19-
'support')
20-
group.addoption('--cov', action='append', default=[], metavar='path',
21-
dest='cov_source',
18+
group = parser.getgroup(
19+
'cov', 'coverage reporting with distributed testing support')
20+
21+
group.addoption('--cov', action='append', nargs='?', dest='cov',
22+
const=True, default=[],
23+
help='Enable coverage plugin.')
24+
group.addoption('--cov-source', action='append', default=[],
25+
metavar='path', dest='cov_source',
2226
help='measure coverage for filesystem path '
2327
'(multi-allowed)')
2428
group.addoption('--cov-report', action='append', default=[],
@@ -41,14 +45,23 @@ def pytest_addoption(parser):
4145
@pytest.mark.tryfirst
4246
def pytest_load_initial_conftests(early_config, parser, args):
4347
ns = parser.parse_known_args(args)
44-
if ns.cov_source:
48+
if ns.cov and ns.cov != [True]:
49+
print ('Deprecation warning: --cov shouldn\'t be used '
50+
'with additional source arguments anymore. Use '
51+
'--cov-source instead.')
52+
ns.cov_source.extend(ns.cov)
53+
54+
if not ns.cov_source:
55+
ns.cov_source = None
56+
57+
if ns.cov:
4558
plugin = CovPlugin(ns, early_config.pluginmanager)
4659
early_config.pluginmanager.register(plugin, '_cov')
4760

4861

4962
def pytest_configure(config):
5063
"""Activate coverage plugin if appropriate."""
51-
if config.getvalue('cov_source'):
64+
if config.getvalue('cov'):
5265
if not config.pluginmanager.hasplugin('_cov'):
5366
plugin = CovPlugin(config.option, config.pluginmanager,
5467
start=False)
@@ -141,7 +154,7 @@ def pytest_terminal_summary(self, terminalreporter):
141154
if self.cov_controller is None:
142155
return
143156
if not (self.failed and self.options.no_cov_on_fail):
144-
total = self.cov_controller.summary(terminalreporter._tw)
157+
total = self.cov_controller.summary(terminalreporter.writer)
145158
if total < self.options.cov_min:
146159
raise CoverageError(('Required test coverage of %d%% not '
147160
'reached. Total coverage: %.2f%%')

pytest-cov/test_pytest_cov.py

Lines changed: 76 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ def test_foo():
2525
assert False
2626
'''
2727

28+
COVERAGERC_SOURCE = '''\
29+
[run]
30+
source = .
31+
'''
32+
2833
SCRIPT_CHILD = '''
2934
import sys
3035
@@ -96,7 +101,7 @@ def test_central(testdir):
96101
script = testdir.makepyfile(SCRIPT)
97102

98103
result = testdir.runpytest('-v',
99-
'--cov=%s' % script.dirpath(),
104+
'--cov', '--cov-source=%s' % script.dirpath(),
100105
'--cov-report=term-missing',
101106
script)
102107

@@ -108,11 +113,52 @@ def test_central(testdir):
108113
assert result.ret == 0
109114

110115

116+
def test_central_nonspecific(testdir):
117+
script = testdir.makepyfile(SCRIPT)
118+
119+
result = testdir.runpytest('-v',
120+
'--cov',
121+
'--cov-report=term-missing',
122+
script)
123+
124+
result.stdout.fnmatch_lines([
125+
'*- coverage: platform *, python * -*',
126+
'test_central_nonspecific * %s *' % SCRIPT_RESULT,
127+
'*10 passed*'
128+
])
129+
130+
# multi-module coverage report
131+
assert result.stdout.lines[-3].startswith('TOTAL ')
132+
133+
assert result.ret == 0
134+
135+
136+
def test_central_coveragerc(testdir):
137+
script = testdir.makepyfile(SCRIPT)
138+
testdir.tmpdir.join('.coveragerc').write(COVERAGERC_SOURCE)
139+
140+
result = testdir.runpytest('-v',
141+
'--cov',
142+
'--cov-report=term-missing',
143+
script)
144+
145+
result.stdout.fnmatch_lines([
146+
'*- coverage: platform *, python * -*',
147+
'test_central_coveragerc * %s *' % SCRIPT_RESULT,
148+
'*10 passed*',
149+
])
150+
151+
# single-module coverage report
152+
assert result.stdout.lines[-3].startswith('test_central_coveragerc ')
153+
154+
assert result.ret == 0
155+
156+
111157
def test_no_cov_on_fail(testdir):
112158
script = testdir.makepyfile(SCRIPT_FAIL)
113159

114160
result = testdir.runpytest('-v',
115-
'--cov=%s' % script.dirpath(),
161+
'--cov', '--cov-source=%s' % script.dirpath(),
116162
'--cov-report=term-missing',
117163
'--no-cov-on-fail',
118164
script)
@@ -125,7 +171,7 @@ def test_dist_collocated(testdir):
125171
script = testdir.makepyfile(SCRIPT)
126172

127173
result = testdir.runpytest('-v',
128-
'--cov=%s' % script.dirpath(),
174+
'--cov', '--cov-source=%s' % script.dirpath(),
129175
'--cov-report=term-missing',
130176
'--dist=load',
131177
'--tx=2*popen',
@@ -145,7 +191,7 @@ def test_dist_not_collocated(testdir):
145191
dir2 = testdir.mkdir('dir2')
146192

147193
result = testdir.runpytest('-v',
148-
'--cov=%s' % script.dirpath(),
194+
'--cov', '--cov-source=%s' % script.dirpath(),
149195
'--cov-report=term-missing',
150196
'--dist=load',
151197
'--tx=popen//chdir=%s' % dir1,
@@ -167,7 +213,7 @@ def test_central_subprocess(testdir):
167213
parent_script = scripts.dirpath().join('parent_script.py')
168214

169215
result = testdir.runpytest('-v',
170-
'--cov=%s' % scripts.dirpath(),
216+
'--cov', '--cov-source=%s' % scripts.dirpath(),
171217
'--cov-report=term-missing',
172218
parent_script)
173219

@@ -185,7 +231,7 @@ def test_dist_subprocess_collocated(testdir):
185231
parent_script = scripts.dirpath().join('parent_script.py')
186232

187233
result = testdir.runpytest('-v',
188-
'--cov=%s' % scripts.dirpath(),
234+
'--cov', '--cov-source=%s' % scripts.dirpath(),
189235
'--cov-report=term-missing',
190236
'--dist=load',
191237
'--tx=2*popen',
@@ -209,7 +255,7 @@ def test_dist_subprocess_not_collocated(testdir, tmpdir):
209255
dir2 = tmpdir.mkdir('dir2')
210256

211257
result = testdir.runpytest('-v',
212-
'--cov=%s' % scripts.dirpath(),
258+
'--cov', '--cov-source=%s' % scripts.dirpath(),
213259
'--cov-report=term-missing',
214260
'--dist=load',
215261
'--tx=popen//chdir=%s' % dir1,
@@ -230,7 +276,7 @@ def test_empty_report(testdir):
230276
script = testdir.makepyfile(SCRIPT)
231277

232278
result = testdir.runpytest('-v',
233-
'--cov=non_existent_module',
279+
'--cov', '--cov-source=non_existent_module',
234280
'--cov-report=term-missing',
235281
script)
236282

@@ -253,7 +299,7 @@ def test_dist_missing_data(testdir):
253299
script = testdir.makepyfile(SCRIPT)
254300

255301
result = testdir.runpytest('-v',
256-
'--cov=%s' % script.dirpath(),
302+
'--cov', '--cov-source=%s' % script.dirpath(),
257303
'--cov-report=term-missing',
258304
'--dist=load',
259305
'--tx=popen//python=%s' % exe,
@@ -269,7 +315,7 @@ def test_funcarg(testdir):
269315
script = testdir.makepyfile(SCRIPT_FUNCARG)
270316

271317
result = testdir.runpytest('-v',
272-
'--cov=%s' % script.dirpath(),
318+
'--cov', '--cov-source=%s' % script.dirpath(),
273319
'--cov-report=term-missing',
274320
script)
275321

@@ -299,7 +345,7 @@ def test_multiprocessing_subprocess(testdir):
299345
script = testdir.makepyfile(MULTIPROCESSING_SCRIPT)
300346

301347
result = testdir.runpytest('-v',
302-
'--cov=%s' % script.dirpath(),
348+
'--cov', '--cov-source=%s' % script.dirpath(),
303349
'--cov-report=term-missing',
304350
script)
305351

@@ -340,7 +386,7 @@ def test_cover_conftest(testdir):
340386
testdir.makeconftest(CONFTEST)
341387
script = testdir.makepyfile(BASIC_TEST)
342388
result = testdir.runpytest('-v',
343-
'--cov=%s' % script.dirpath(),
389+
'--cov', '--cov-source=%s' % script.dirpath(),
344390
'--cov-report=term-missing',
345391
script)
346392
assert result.ret == 0
@@ -352,7 +398,7 @@ def test_cover_conftest_dist(testdir):
352398
testdir.makeconftest(CONFTEST)
353399
script = testdir.makepyfile(BASIC_TEST)
354400
result = testdir.runpytest('-v',
355-
'--cov=%s' % script.dirpath(),
401+
'--cov', '--cov-source=%s' % script.dirpath(),
356402
'--cov-report=term-missing',
357403
'--dist=load',
358404
'--tx=2*popen',
@@ -388,7 +434,7 @@ def test_coveragerc(testdir):
388434
script = testdir.makepyfile(EXCLUDED_TEST)
389435
result = testdir.runpytest('-v',
390436
'--cov-config=coveragerc',
391-
'--cov=%s' % script.dirpath(),
437+
'--cov', '--cov-source=%s' % script.dirpath(),
392438
'--cov-report=term-missing',
393439
script)
394440
assert result.ret == 0
@@ -400,7 +446,7 @@ def test_coveragerc_dist(testdir):
400446
script = testdir.makepyfile(EXCLUDED_TEST)
401447
result = testdir.runpytest('-v',
402448
'--cov-config=coveragerc',
403-
'--cov=%s' % script.dirpath(),
449+
'--cov', '--cov-source=%s' % script.dirpath(),
404450
'--cov-report=term-missing',
405451
'-n', '2',
406452
script)
@@ -422,7 +468,7 @@ def test_basic():
422468
def test_clear_environ(testdir):
423469
script = testdir.makepyfile(CLEAR_ENVIRON_TEST)
424470
result = testdir.runpytest('-v',
425-
'--cov=%s' % script.dirpath(),
471+
'--cov', '--cov-source=%s' % script.dirpath(),
426472
'--cov-report=term-missing',
427473
script)
428474
assert result.ret == 0
@@ -445,7 +491,7 @@ def test_dist_boxed(testdir):
445491
script = testdir.makepyfile(SCRIPT_SIMPLE)
446492

447493
result = testdir.runpytest('-v',
448-
'--cov=%s' % script.dirpath(),
494+
'--cov', '--cov-source=%s' % script.dirpath(),
449495
'--boxed',
450496
script)
451497

@@ -461,3 +507,16 @@ def test_not_started_plugin_does_not_fail(testdir):
461507
plugin = pytest_cov.CovPlugin(None, None, start=False)
462508
plugin.pytest_sessionfinish(None, None)
463509
plugin.pytest_terminal_summary(None)
510+
511+
512+
def test_deprecation_warning(testdir):
513+
script = testdir.makepyfile(SCRIPT)
514+
515+
result = testdir.runpytest('-v',
516+
'--cov=%s' % script.dirpath(),
517+
script)
518+
519+
result.stdout.fnmatch_lines([
520+
'Deprecation warning: * --cov-source instead*'
521+
])
522+
assert result.ret == 0

pytest-cov/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ usedevelop = True
66
setenv =
77
PYTHONHASHSEED = random
88
deps =
9-
{env:COV_CORE_DEP:cov-core}
9+
{env:COV_CORE_DEP:../cov-core}
1010
pytest
1111
pytest-xdist
1212
virtualenv

0 commit comments

Comments
 (0)