From a89f40e4c01fcb6c5a50eb42dc372454446693eb Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 4 Nov 2021 07:54:32 -0400 Subject: refactor(test): make traceback checks a bit flexible Python 3.11 made a traceback look like this: Traceback (most recent call last): File "{path}", line 8, in print(sys.argv[1]) ~~~~~~~~^^^ IndexError: list index out of range We needed to not care if that tilde-caret line was present or not. --- tests/test_cmdline.py | 9 +++++---- tests/test_process.py | 9 ++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 9e987760..acd5fa29 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -956,10 +956,11 @@ class CmdMainTest(CoverageTest): assert ret == 1 out, err = self.stdouterr() assert out == "" - err = err.split('\n') - assert err[0] == 'Traceback (most recent call last):' - assert err[-3] == ' raise Exception("oh noes!")' - assert err[-2] == 'Exception: oh noes!' + print(err) + err = err.splitlines(keepends=True) + assert err[0] == 'Traceback (most recent call last):\n' + assert ' raise Exception("oh noes!")\n' in err + assert err[-1] == 'Exception: oh noes!\n' def test_internalraise(self): with pytest.raises(ValueError, match="coverage is broken"): diff --git a/tests/test_process.py b/tests/test_process.py index e048bdc2..b8f268f7 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -1412,12 +1412,15 @@ class YankedDirectoryTest(CoverageTest): self.make_file("bug806.py", self.BUG_806) out = self.run_command("coverage run bug806.py") path = python_reported_file('bug806.py') - assert out == textwrap.dedent("""\ + # Python 3.11 adds an extra line to the traceback. + # Check that the lines we expect are there. + lines = textwrap.dedent(f"""\ Traceback (most recent call last): - File "{}", line 8, in + File "{path}", line 8, in print(sys.argv[1]) IndexError: list index out of range - """.format(path)) + """).splitlines(keepends=True) + assert all(line in out for line in lines) def possible_pth_dirs(): -- cgit v1.2.1