Skip to content

Commit c1e01c2

Browse files
authored
Merge pull request #4931 from blueyed/linematcher-list
pytester: LineMatcher: assert lines
2 parents 33d4c96 + 5e27ea5 commit c1e01c2

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

changelog/4931.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytester's ``LineMatcher`` asserts that the passed lines are a sequence.

src/_pytest/pytester.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from _pytest.capture import MultiCapture
2626
from _pytest.capture import SysCapture
2727
from _pytest.compat import safe_str
28+
from _pytest.compat import Sequence
2829
from _pytest.main import EXIT_INTERRUPTED
2930
from _pytest.main import EXIT_OK
3031
from _pytest.main import Session
@@ -1325,6 +1326,7 @@ def _match_lines(self, lines2, match_func, match_nickname):
13251326
will be logged to stdout when a match occurs
13261327
13271328
"""
1329+
assert isinstance(lines2, Sequence)
13281330
lines2 = self._getlines(lines2)
13291331
lines1 = self.lines[:]
13301332
nextline = None

testing/test_pytester.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from _pytest.main import EXIT_TESTSFAILED
1818
from _pytest.pytester import CwdSnapshot
1919
from _pytest.pytester import HookRecorder
20+
from _pytest.pytester import LineMatcher
2021
from _pytest.pytester import SysModulesSnapshot
2122
from _pytest.pytester import SysPathsSnapshot
2223

@@ -453,3 +454,18 @@ def test_timeout():
453454
)
454455
with pytest.raises(testdir.TimeoutExpired):
455456
testdir.runpytest_subprocess(testfile, timeout=1)
457+
458+
459+
def test_linematcher_with_nonlist():
460+
"""Test LineMatcher with regard to passing in a set (accidentally)."""
461+
lm = LineMatcher([])
462+
463+
with pytest.raises(AssertionError):
464+
lm.fnmatch_lines(set())
465+
with pytest.raises(AssertionError):
466+
lm.fnmatch_lines({})
467+
lm.fnmatch_lines([])
468+
lm.fnmatch_lines(())
469+
470+
assert lm._getlines({}) == {}
471+
assert lm._getlines(set()) == set()

0 commit comments

Comments
 (0)