summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTanvi Mehta <tanvimehta@Tanvis-MacBook-Pro-2.local>2020-10-07 21:51:28 -0700
committerTanvi Mehta <tanvimehta@Tanvis-MacBook-Pro-2.local>2020-10-07 21:51:28 -0700
commit43b1eb3c9eef41c9e7fdc7c56aac668ad661c9a3 (patch)
tree353d066826ecba6a2dfda37c8ed1c7c1f373e830 /src
parent5acc55e8386a6245c56780221cf35cc43fd02253 (diff)
downloadpytest-43b1eb3c9eef41c9e7fdc7c56aac668ad661c9a3.tar.gz
Use instead of a in Issue #7868
Use `collections.Counter` instead of a `dict` in `terminal.py` Issue #7868
Diffstat (limited to 'src')
-rw-r--r--src/_pytest/terminal.py11
1 files 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()