Skip to content

Commit

Permalink
Fix / ignore mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry-git committed Jun 19, 2024
1 parent 6a6dcbb commit 3463eb7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/pytest_split/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ def least_duration(
items_with_durations_indexed, key=lambda tup: tup[1], reverse=True
)

selected: "List[List[Tuple[nodes.Item, int]]]" = [[] for _ in range(splits)]
deselected: "List[List[nodes.Item]]" = [[] for _ in range(splits)]
duration: "List[float]" = [0 for _ in range(splits)]
selected: List[List[Tuple[nodes.Item, int]]] = [[] for _ in range(splits)]
deselected: List[List[nodes.Item]] = [[] for _ in range(splits)]
duration: List[float] = [0 for _ in range(splits)]

# create a heap of the form (summed_durations, group_index)
heap: "List[Tuple[float, int]]" = [(0, i) for i in range(splits)]
heap: List[Tuple[float, int]] = [(0, i) for i in range(splits)]
heapq.heapify(heap)
for item, item_duration, original_index in sorted_items_with_durations:
# get group with smallest sum
Expand Down Expand Up @@ -102,9 +102,9 @@ def duration_based_chunks(
items_with_durations = _get_items_with_durations(items, durations)
time_per_group = sum(map(itemgetter(1), items_with_durations)) / splits

selected: "List[List[nodes.Item]]" = [[] for i in range(splits)]
deselected: "List[List[nodes.Item]]" = [[] for i in range(splits)]
duration: "List[float]" = [0 for i in range(splits)]
selected: List[List[nodes.Item]] = [[] for i in range(splits)]
deselected: List[List[nodes.Item]] = [[] for i in range(splits)]
duration: List[float] = [0 for i in range(splits)]

group_idx = 0
for item, item_duration in items_with_durations:
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_split/ipynb_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pytest_split.algorithms import TestGroup


def ensure_ipynb_compatibility(group: "TestGroup", items: list) -> None:
def ensure_ipynb_compatibility(group: "TestGroup", items: list) -> None: # type: ignore[type-arg]
"""
Ensures that group doesn't contain partial IPy notebook cells.
Expand Down
10 changes: 4 additions & 6 deletions src/pytest_split/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from _pytest import nodes
from _pytest.config import Config
from _pytest.config.argparsing import Parser
from _pytest.main import ExitCode
from _pytest.main import ExitCode # type: ignore[attr-defined]


# Ugly hack for freezegun compatibility: https://github.com/spulec/freezegun/issues/286
Expand Down Expand Up @@ -193,9 +193,9 @@ def pytest_sessionfinish(self) -> None:
https://github.com/pytest-dev/pytest/blob/main/src/_pytest/main.py#L308
"""
terminal_reporter = self.config.pluginmanager.get_plugin("terminalreporter")
test_durations: "Dict[str, float]" = {}
test_durations: Dict[str, float] = {}

for test_reports in terminal_reporter.stats.values():
for test_reports in terminal_reporter.stats.values(): # type: ignore[union-attr]
for test_report in test_reports:
if isinstance(test_report, TestReport):
# These ifs be removed after this is solved: # https://github.com/spulec/freezegun/issues/286
Expand Down Expand Up @@ -224,8 +224,6 @@ def pytest_sessionfinish(self) -> None:
json.dump(self.cached_durations, f, sort_keys=True, indent=4)

message = self.writer.markup(
"\n\n[pytest-split] Stored test durations in {}".format(
self.config.option.durations_path
)
f"\n\n[pytest-split] Stored test durations in {self.config.option.durations_path}"
)
self.writer.line(message)
2 changes: 1 addition & 1 deletion tests/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test__split_tests_same_set_regardless_of_order(self):
items = [item(t) for t in tests]
algo = Algorithms["least_duration"].value
for n in (2, 3, 4):
selected_each: "List[Set[Item]]" = [set() for _ in range(n)]
selected_each: List[Set[Item]] = [set() for _ in range(n)]
for order in itertools.permutations(items):
splits = algo(splits=n, items=order, durations=durations)
for i, group in enumerate(splits):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import ClassVar

import pytest
from _pytest.main import ExitCode
from _pytest.main import ExitCode # type: ignore[attr-defined]

pytest_plugins = ["pytester"]

Expand Down

0 comments on commit 3463eb7

Please sign in to comment.