Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sondrelg committed May 31, 2021
1 parent 552cfa0 commit e7858aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ "3.6", "3.7", "3.8", "3.9", ] # "3.10.0-beta.1"
python-version: [ "3.6", "3.7", "3.8", "3.9" ]
pytest-version: [ "4", "5", "6" ]
steps:
- name: Check out repository
Expand Down
24 changes: 3 additions & 21 deletions src/pytest_split/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ def pytest_configure(config: "Config") -> None:


class Base:
cache_file = "cache/pytest-split"

def __init__(self, config: "Config") -> None:
"""
Load cache and configure plugin.
Expand Down Expand Up @@ -116,17 +114,15 @@ def pytest_collection_modifyitems(self, config: "Config", items: "List[nodes.Ite
See https://github.com/pytest-dev/pytest/blob/main/src/_pytest/main.py#L670.
"""
# Load plugin arguments
splits: int = config.option.splits
group: int = config.option.group

selected_tests, deselected_tests = self._split_tests(splits, group, items, self.cached_durations)

items[:] = selected_tests # type: ignore
items[:] = selected_tests
config.hook.pytest_deselected(items=deselected_tests)

message = self.writer.markup(f"\n\nRunning group {group}/{splits}\n")
self.writer.line(message)
self.writer.line(self.writer.markup(f"\n\nRunning group {group}/{splits}\n"))
return None

@staticmethod
Expand All @@ -137,21 +133,7 @@ def _split_tests(
stored_durations: dict,
) -> "Tuple[list, list]":
"""
Split tests by runtime.
The splitting logic is very simple. We find out what our threshold runtime
is per group, then start adding tests (slowest tests ordered first) until we
get close to the threshold runtime per group. We then reverse the ordering and
add the fastest tests available until we go just *beyond* the threshold.
The choice we're making is to overload the first groups a little bit. The reason
this reasonable is that ci-providers like GHA will usually spin up the first
groups first, meaning that if you had a perfect test split, the first groups
would still finish first. The *overloading* is also minimal, so shouldn't
matter in most cases.
After assigning tests to each group we select the group we're in
and deselect all remaining tests.
Split tests into groups by runtime.
:param splits: How many groups we're splitting in.
:param group: Which group this run represents.
Expand Down

0 comments on commit e7858aa

Please sign in to comment.