Skip to content

Commit 4836761

Browse files
committed
test: nicer way to test debug=pybehave
1 parent 4864c4f commit 4836761

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

tests/test_cmdline.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
"""Test cmdline.py for coverage.py."""
55

6+
import ast
67
import pprint
78
import re
89
import sys
@@ -20,7 +21,7 @@
2021
from coverage.version import __url__
2122

2223
from tests.coveragetest import CoverageTest, OK, ERR, command_line
23-
from tests.helpers import os_sep
24+
from tests.helpers import os_sep, re_line
2425

2526

2627
class BaseCmdLineTest(CoverageTest):
@@ -298,8 +299,8 @@ def test_debug_pybehave(self):
298299
assert " CPYTHON:" in out
299300
assert " PYVERSION:" in out
300301
assert " pep626:" in out
301-
pyversion = next(l for l in out.splitlines() if " PYVERSION:" in l)
302-
vtuple = eval(pyversion.partition(":")[-1]) # pylint: disable=eval-used
302+
pyversion = re_line(r" PYVERSION:", out)
303+
vtuple = ast.literal_eval(pyversion.partition(":")[-1])
303304
assert vtuple[:5] == sys.version_info
304305

305306
def test_debug_premain(self):

tests/test_debug.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
"""Tests of coverage/debug.py"""
55

6+
import ast
67
import io
78
import os
89
import re
@@ -202,8 +203,8 @@ def test_debug_pybehave(self):
202203
out_text = self.f1_debug_output(["pybehave"])
203204
out_lines = out_text.splitlines()
204205
assert 10 < len(out_lines) < 40
205-
pyversion = next(l for l in out_lines if " PYVERSION:" in l)
206-
vtuple = eval(pyversion.partition(":")[-1]) # pylint: disable=eval-used
206+
pyversion = re_line(r" PYVERSION:", out_text)
207+
vtuple = ast.literal_eval(pyversion.partition(":")[-1].strip())
207208
assert vtuple[:5] == sys.version_info
208209

209210

0 commit comments

Comments
 (0)