Skip to content

Commit

Permalink
Add mypy and flake8-type-checking config
Browse files Browse the repository at this point in the history
  • Loading branch information
sondrelg committed May 31, 2021
1 parent fc2badf commit bd6204c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
28 changes: 16 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@ repos:
hooks:
- id: black
args: ['--quiet']
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
additional_dependencies: [
'flake8-bugbear',
'flake8-comprehensions',
'flake8-deprecated',
'flake8-print',
'flake8-annotations',
'flake8-type-checking',
]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
Expand All @@ -31,3 +19,19 @@ repos:
- id: trailing-whitespace
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
additional_dependencies: [
'flake8-bugbear',
'flake8-comprehensions',
'flake8-deprecated',
'flake8-print',
'flake8-type-checking',
]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.812'
hooks:
- id: mypy
additional_dependencies: [django, djangorestframework, inflection, openapi-spec-validator, prance, pyYAML, django-stubs, djangorestframework-stubs, drf_yasg, drf-spectacular]
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[flake8]
max-line-length = 88
exclude =
tests/*
enable-extensions=TC,TC1
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
install_requires=["pytest"],
extras_require={"testing": tests_require},
classifiers=[
"Development Status :: 4 - Beta"
"Intended Audience :: Developers",
"Development Status :: 4 - Beta" "Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
Expand Down
23 changes: 12 additions & 11 deletions src/pytest_split/plugin.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import json
import os
from collections import defaultdict, OrderedDict
from typing import TYPE_CHECKING, Tuple
from typing import TYPE_CHECKING

from _pytest.config import create_terminal_writer
from _pytest.main import Session

if TYPE_CHECKING:
from typing import Generator, List
from typing import List, Tuple
from _pytest.config.argparsing import Parser
from _pytest.main import Session

from _pytest import nodes
from _pytest.config import Config
Expand Down Expand Up @@ -52,22 +52,20 @@ def pytest_addoption(parser: "Parser") -> None:
)


def pytest_collection_modifyitems(
config: "Config", items: "List[nodes.Item]"
) -> "Generator[None, None, None]":
def pytest_collection_modifyitems(config: "Config", items: "List[nodes.Item]") -> None:
splits = config.option.splits
group = config.option.group
store_durations = config.option.store_durations
durations_report_path = config.option.durations_path

if any((splits, group)):
if not all((splits, group)):
return
return None
if not os.path.isfile(durations_report_path):
return
return None
if store_durations:
# Don't split if we are storing durations
return
return None
total_tests_count = len(items)
if splits and group:
with open(durations_report_path) as f:
Expand All @@ -86,13 +84,14 @@ def pytest_collection_modifyitems(
)
)
terminal_reporter.write(message)
return None


def pytest_sessionfinish(session: "Session") -> None:
if session.config.option.store_durations:
report_path = session.config.option.durations_path
terminal_reporter = session.config.pluginmanager.get_plugin("terminalreporter")
durations = defaultdict(float)
durations: dict = defaultdict(float)
for test_reports in terminal_reporter.stats.values():
for test_report in test_reports:
if hasattr(test_report, "duration"):
Expand Down Expand Up @@ -124,7 +123,9 @@ def _calculate_suite_start_and_end_idx(
splits: int, group: int, items: "List[nodes.Item]", stored_durations: OrderedDict
) -> Tuple[int, int]:
item_node_ids = [item.nodeid for item in items]
stored_durations = {k: v for k, v in stored_durations.items() if k in item_node_ids}
stored_durations = OrderedDict(
{k: v for k, v in stored_durations.items() if k in item_node_ids}
)
avg_duration_per_test = sum(stored_durations.values()) / len(stored_durations)

durations = OrderedDict()
Expand Down

0 comments on commit bd6204c

Please sign in to comment.