From 94400a68b4a7ddc31b90092297d288c02ae2b33c Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Tue, 5 May 2020 23:08:44 +0300 Subject: [PATCH] terminal: fix non-deterministic warning summary order in Python 3.5 In Python 3.5, collections.Counter() does not preserve insertion order. --- src/_pytest/terminal.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index bf1b65ed9..9c88ca0ca 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -854,9 +854,12 @@ class TerminalReporter: if len(locations) < 10: return "\n".join(map(str, locations)) - counts_by_filename = collections.Counter( - str(loc).split("::", 1)[0] for loc in locations - ) + counts_by_filename = ( + collections.OrderedDict() + ) # type: collections.OrderedDict[str, int] + for loc in locations: + key = str(loc).split("::", 1)[0] + counts_by_filename[key] = counts_by_filename.get(key, 0) + 1 return "\n".join( "{}: {} warning{}".format(k, v, "s" if v > 1 else "") for k, v in counts_by_filename.items()