From 169972546b699f01813131d5356d0edcfc739343 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 28 Feb 2021 08:28:58 -0500 Subject: [PATCH] fix: improve an error message. #803 Fixes #803. --- CHANGES.rst | 4 ++++ coverage/sqldata.py | 4 ++-- tests/test_data.py | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 201f1d069..82f174dd3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -37,6 +37,10 @@ Unreleased - It has a little more room for line numbers so that 4-digit numbers work well, fixing `issue 1124`_. +- Improved the error message when combining line and branch data, so that users + will be more likely to understand what's happening, closing `issue 803`_. + +.. _issue 803: https://github.com/nedbat/coveragepy/issues/803 .. _issue 1108: https://github.com/nedbat/coveragepy/issues/1108 .. _pull request 1110: https://github.com/nedbat/coveragepy/pull/1110 .. _issue 1123: https://github.com/nedbat/coveragepy/issues/1123 diff --git a/coverage/sqldata.py b/coverage/sqldata.py index b28b83b4f..a150fdfd0 100644 --- a/coverage/sqldata.py +++ b/coverage/sqldata.py @@ -486,9 +486,9 @@ def _choose_lines_or_arcs(self, lines=False, arcs=False): assert lines or arcs assert not (lines and arcs) if lines and self._has_arcs: - raise CoverageException("Can't add lines to existing arc data") + raise CoverageException("Can't add line measurements to existing branch data") if arcs and self._has_lines: - raise CoverageException("Can't add arcs to existing line data") + raise CoverageException("Can't add branch measurements to existing line data") if not self._has_arcs and not self._has_lines: self._has_lines = lines self._has_arcs = arcs diff --git a/tests/test_data.py b/tests/test_data.py index fe37bd9e7..eac9c36fa 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -159,13 +159,15 @@ def test_ok_to_add_arcs_twice(self): def test_cant_add_arcs_with_lines(self): covdata = CoverageData() covdata.add_lines(LINES_1) - with pytest.raises(CoverageException, match="Can't add arcs to existing line data"): + msg = "Can't add branch measurements to existing line data" + with pytest.raises(CoverageException, match=msg): covdata.add_arcs(ARCS_3) def test_cant_add_lines_with_arcs(self): covdata = CoverageData() covdata.add_arcs(ARCS_3) - with pytest.raises(CoverageException, match="Can't add lines to existing arc data"): + msg = "Can't add line measurements to existing branch data" + with pytest.raises(CoverageException, match=msg): covdata.add_lines(LINES_1) def test_touch_file_with_lines(self):