From 0b6258ab5bce985b14f28aa9e7bfe828b1d5b8c3 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 23 Jan 2020 12:54:52 +0100 Subject: [PATCH] PyCollector.collect: use explicit cast to `str` Ref: https://github.com/pytest-dev/pytest/pull/6521#pullrequestreview-347234792 --- src/_pytest/python.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 3d2916c83..82dca3bcc 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -369,7 +369,12 @@ class PyCollector(PyobjMixin, nodes.Collector): if not isinstance(res, list): res = [res] values.extend(res) - values.sort(key=lambda item: item.reportinfo()[:2]) + + def sort_key(item): + fspath, lineno, _ = item.reportinfo() + return (str(fspath), lineno) + + values.sort(key=sort_key) return values def _makeitem(self, name, obj):