Skip to content
Closed
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
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Authors
* Federico Ceratto - http://firelet.net/
* Josh Kalderimis - http://blog.cookiestack.com/
* Ionel Cristian Mărieș - http://blog.ionelmc.ro
* Christian Ledermann - https://github.com/cleder
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ tests run on Travis-CI could produce a .coverage file for use with Coveralls.
Coverage Data File
==================

The data file is erased at the beginning of testing to ensure clean data for each test run.
The data file is erased at the beginning of testing to ensure clean data for each test run. If you
need to combine the overage of several test runs you can use the ``--cov-append`` option to append
this coverage data to coverage data from previous test runs.

The data file is left at the end of testing so that it is possible to use normal coverage tools to
examine it.
Expand Down
5 changes: 4 additions & 1 deletion src/pytest_cov/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ def start(self):

self.cov = coverage.coverage(source=self.cov_source,
config_file=self.cov_config)
self.cov.erase()
if self.config.option.append_coverage:
self.cov.load()
else:
self.cov.erase()
self.cov.start()
self.set_env()

Expand Down
4 changes: 4 additions & 0 deletions src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def pytest_addoption(parser):
'default: False')
group.addoption('--cov-fail-under', action='store', metavar='MIN', type='int',
help='Fail if the total coverage is less than MIN.')
group.addoption('--cov-append', action='store_true', default=False,
dest='append_coverage',
help='do not delete coverage but append to current, '
'default: False')


@pytest.mark.tryfirst
Expand Down
43 changes: 43 additions & 0 deletions tests/test_pytest_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ def test_foo():
assert False
'''

SCRIPT2 = '''
#

def test_bar():
x = True
assert x

'''


COVERAGERC_SOURCE = '''\
[run]
source = .
Expand Down Expand Up @@ -717,3 +727,36 @@ def test_external_data_file_negative(testdir):
script)
assert result.ret == 0
assert glob.glob(str(testdir.tmpdir.join('.coverage*')))

def test_append_coverage(testdir):
script = testdir.makepyfile(test_1=SCRIPT)
testdir.tmpdir.join('.coveragerc').write("")
result = testdir.runpytest('-v',
'--cov=%s' % script.dirpath(),
script)
size1 = script.dirpath().join('.coverage').size()
assert(size1 > 0)
script.remove()
script2 = testdir.makepyfile(test_2=SCRIPT2)
result = testdir.runpytest('-v', '--cov-append',
'--cov=%s' % script2.dirpath(),
script2)
size2 = script2.dirpath().join('.coverage').size()
assert(size2 > size1)

def test_do_not_append_coverage(testdir):
script = testdir.makepyfile(test_1=SCRIPT)
testdir.tmpdir.join('.coveragerc').write("")
result = testdir.runpytest('-v',
'--cov=%s' % script.dirpath(),
script)
size1 = script.dirpath().join('.coverage').size()
assert(size1 > 0)
script.remove()
script2 = testdir.makepyfile(test_2=SCRIPT2)
result = testdir.runpytest('-v',
'--cov=%s' % script2.dirpath(),
script2)
size2 = script2.dirpath().join('.coverage').size()
assert(size1 > size2)
assert(size2 > 0)