Skip to content

Commit e41128f

Browse files
committed
chore: add missing type hints
add missing type hints to code
1 parent 3a046c8 commit e41128f

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

pytest_rts/pytest/fake_item.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""This module contains a fake pytest item class"""
2+
from _pytest.config import Config
23

34

45
class FakeItem: # pylint: disable=too-few-public-methods
56
"""Fake class"""
67

7-
def __init__(self, config) -> None:
8+
def __init__(self, config: Config) -> None:
89
self.config = config

pytest_rts/pytest/runner_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""This module contains code for running a specific test set"""
22
# pylint: disable=too-few-public-methods
3-
from typing import List
3+
from typing import List, Set
44

55
from _pytest.main import Session
66
from _pytest.nodes import Item
@@ -12,7 +12,7 @@
1212
class RunnerPlugin:
1313
"""Plugin class for pytest"""
1414

15-
def __init__(self, existing_tests) -> None:
15+
def __init__(self, existing_tests: Set[str]) -> None:
1616
"""Set existing tests"""
1717
self.existing_tests = existing_tests
1818

pytest_rts/tests/test_common.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""Tests for common utility functions"""
2+
from typing import cast
3+
24
import pytest
5+
from _pytest.nodes import Item
36

47
from pytest_rts.utils.common import filter_pytest_items, strip_pytest_cov_testname
58

@@ -21,12 +24,12 @@
2124
),
2225
],
2326
)
24-
def test_strip_pytest_cov_testname(testname, expected):
27+
def test_strip_pytest_cov_testname(testname: str, expected: str) -> None:
2528
"""Test pytest-cov testname stripping to actual pytest item.nodeid strings"""
2629
assert strip_pytest_cov_testname(testname) == expected
2730

2831

29-
def test_filter_pytest_items():
32+
def test_filter_pytest_items() -> None:
3033
"""Test for filtering the test set
3134
based on given existing tests
3235
"""
@@ -49,16 +52,16 @@ def get_closest_marker(self, markername: str) -> bool:
4952
return False
5053

5154
collected_items = [
52-
FakePytestItem("test1", "test_func_1", ""),
53-
FakePytestItem("test2", "test_func_2", "skip"),
54-
FakePytestItem("test3", "test_func_3", ""),
55-
FakePytestItem("test4", "test_func_4", "skipif"),
56-
FakePytestItem("test5", "test_func_5", ""),
55+
cast(Item, FakePytestItem("test1", "test_func_1", "")),
56+
cast(Item, FakePytestItem("test2", "test_func_2", "skip")),
57+
cast(Item, FakePytestItem("test3", "test_func_3", "")),
58+
cast(Item, FakePytestItem("test4", "test_func_4", "skipif")),
59+
cast(Item, FakePytestItem("test5", "test_func_5", "")),
5760
]
58-
existing_tests = [
61+
existing_tests = {
5962
"test_func_1",
6063
"test_func_3",
61-
]
64+
}
6265

6366
filtered_items = filter_pytest_items(collected_items, existing_tests)
6467

pytest_rts/tests/test_e2e.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""Integration tests for pytest-rts"""
22
import os
33

4+
from _pytest.pytester import Testdir
45

5-
def test_only_new_functions_are_ran(testdir):
6+
7+
def test_only_new_functions_are_ran(testdir: Testdir) -> None:
68
"""Test case for running pytest-rts when new tests are added
79
and changes are not committed.
810
"""

pytest_rts/utils/common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from _pytest.nodes import Item
66

77

8-
def filter_pytest_items(pytest_items: List[Item], existing_tests) -> List[Item]:
8+
def filter_pytest_items(
9+
pytest_items: List[Item], existing_tests: Set[str]
10+
) -> List[Item]:
911
"""Select pytest items if they are new and not marked as skipped"""
1012
return list(
1113
filter(

0 commit comments

Comments
 (0)