From 43b1eb3c9eef41c9e7fdc7c56aac668ad661c9a3 Mon Sep 17 00:00:00 2001 From: Tanvi Mehta Date: Wed, 7 Oct 2020 21:51:28 -0700 Subject: [PATCH 1/3] Use instead of a in Issue #7868 Use `collections.Counter` instead of a `dict` in `terminal.py` Issue #7868 --- src/_pytest/terminal.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 0e8db20c7..f96169c96 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -8,6 +8,7 @@ import inspect import platform import sys import warnings +from collections import Counter from functools import partial from pathlib import Path from typing import Any @@ -754,10 +755,7 @@ class TerminalReporter: # because later versions are going to get rid of them anyway. if self.config.option.verbose < 0: if self.config.option.verbose < -1: - counts: Dict[str, int] = {} - for item in items: - name = item.nodeid.split("::", 1)[0] - counts[name] = counts.get(name, 0) + 1 + counts = Counter(item.nodeid.split("::", 1)[0] for item in items) for name, count in sorted(counts.items()): self._tw.line("%s: %d" % (name, count)) else: @@ -922,10 +920,7 @@ class TerminalReporter: if len(locations) < 10: return "\n".join(map(str, locations)) - counts_by_filename: Dict[str, int] = {} - for loc in locations: - key = str(loc).split("::", 1)[0] - counts_by_filename[key] = counts_by_filename.get(key, 0) + 1 + counts_by_filename = Counter(str(loc).split("::", 1)[0] for loc in locations) return "\n".join( "{}: {} warning{}".format(k, v, "s" if v > 1 else "") for k, v in counts_by_filename.items() From 779b511bfe10f5e212e761460f36edc8d4e65062 Mon Sep 17 00:00:00 2001 From: Tanvi Mehta Date: Wed, 7 Oct 2020 22:25:27 -0700 Subject: [PATCH 2/3] Fixed formatting --- src/_pytest/terminal.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index f96169c96..ff28be565 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -920,7 +920,9 @@ class TerminalReporter: if len(locations) < 10: return "\n".join(map(str, locations)) - counts_by_filename = Counter(str(loc).split("::", 1)[0] for loc in locations) + counts_by_filename = Counter( + str(loc).split("::", 1)[0] for loc in locations + ) return "\n".join( "{}: {} warning{}".format(k, v, "s" if v > 1 else "") for k, v in counts_by_filename.items() From d0939314648e4168b7e621afebb153485bde28de Mon Sep 17 00:00:00 2001 From: Tanvi Mehta Date: Wed, 7 Oct 2020 22:57:52 -0700 Subject: [PATCH 3/3] Added name to authors list --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index ab84a3e52..37c1e3c06 100644 --- a/AUTHORS +++ b/AUTHORS @@ -275,6 +275,7 @@ Sven-Hendrik Haase Sylvain Marié Tadek Teleżyński Takafumi Arakaki +Tanvi Mehta Tarcisio Fischer Tareq Alayan Ted Xiao