Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/4931.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytester's ``LineMatcher`` asserts that the passed lines are a sequence.
2 changes: 2 additions & 0 deletions src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from _pytest.capture import MultiCapture
from _pytest.capture import SysCapture
from _pytest.compat import safe_str
from _pytest.compat import Sequence
from _pytest.main import EXIT_INTERRUPTED
from _pytest.main import EXIT_OK
from _pytest.main import Session
Expand Down Expand Up @@ -1325,6 +1326,7 @@ def _match_lines(self, lines2, match_func, match_nickname):
will be logged to stdout when a match occurs

"""
assert isinstance(lines2, Sequence)
lines2 = self._getlines(lines2)
lines1 = self.lines[:]
nextline = None
Expand Down
16 changes: 16 additions & 0 deletions testing/test_pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from _pytest.main import EXIT_TESTSFAILED
from _pytest.pytester import CwdSnapshot
from _pytest.pytester import HookRecorder
from _pytest.pytester import LineMatcher
from _pytest.pytester import SysModulesSnapshot
from _pytest.pytester import SysPathsSnapshot

Expand Down Expand Up @@ -453,3 +454,18 @@ def test_timeout():
)
with pytest.raises(testdir.TimeoutExpired):
testdir.runpytest_subprocess(testfile, timeout=1)


def test_linematcher_with_nonlist():
"""Test LineMatcher with regard to passing in a set (accidentally)."""
lm = LineMatcher([])

with pytest.raises(AssertionError):
lm.fnmatch_lines(set())
with pytest.raises(AssertionError):
lm.fnmatch_lines({})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a dict, it does validate the test but it isn't what the docstring says ;)

lm.fnmatch_lines([])
lm.fnmatch_lines(())

assert lm._getlines({}) == {}
assert lm._getlines(set()) == set()