Skip to content

Commit 1699725

Browse files
committed
fix: improve an error message. #803
Fixes #803.
1 parent 3f38567 commit 1699725

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Unreleased
3737
- It has a little more room for line numbers so that 4-digit numbers work
3838
well, fixing `issue 1124`_.
3939

40+
- Improved the error message when combining line and branch data, so that users
41+
will be more likely to understand what's happening, closing `issue 803`_.
42+
43+
.. _issue 803: https://github.com/nedbat/coveragepy/issues/803
4044
.. _issue 1108: https://github.com/nedbat/coveragepy/issues/1108
4145
.. _pull request 1110: https://github.com/nedbat/coveragepy/pull/1110
4246
.. _issue 1123: https://github.com/nedbat/coveragepy/issues/1123

coverage/sqldata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,9 @@ def _choose_lines_or_arcs(self, lines=False, arcs=False):
486486
assert lines or arcs
487487
assert not (lines and arcs)
488488
if lines and self._has_arcs:
489-
raise CoverageException("Can't add lines to existing arc data")
489+
raise CoverageException("Can't add line measurements to existing branch data")
490490
if arcs and self._has_lines:
491-
raise CoverageException("Can't add arcs to existing line data")
491+
raise CoverageException("Can't add branch measurements to existing line data")
492492
if not self._has_arcs and not self._has_lines:
493493
self._has_lines = lines
494494
self._has_arcs = arcs

tests/test_data.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,15 @@ def test_ok_to_add_arcs_twice(self):
159159
def test_cant_add_arcs_with_lines(self):
160160
covdata = CoverageData()
161161
covdata.add_lines(LINES_1)
162-
with pytest.raises(CoverageException, match="Can't add arcs to existing line data"):
162+
msg = "Can't add branch measurements to existing line data"
163+
with pytest.raises(CoverageException, match=msg):
163164
covdata.add_arcs(ARCS_3)
164165

165166
def test_cant_add_lines_with_arcs(self):
166167
covdata = CoverageData()
167168
covdata.add_arcs(ARCS_3)
168-
with pytest.raises(CoverageException, match="Can't add lines to existing arc data"):
169+
msg = "Can't add line measurements to existing branch data"
170+
with pytest.raises(CoverageException, match=msg):
169171
covdata.add_lines(LINES_1)
170172

171173
def test_touch_file_with_lines(self):

0 commit comments

Comments
 (0)