Skip to content

Commit 53a6190

Browse files
committed
Drop support for Python 3.8
1 parent 5aa9e9c commit 53a6190

File tree

7 files changed

+24
-33
lines changed

7 files changed

+24
-33
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
strategy:
3838
fail-fast: false
3939
matrix:
40-
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14-dev"]
40+
python: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
4141
os: [ubuntu-latest, windows-latest]
4242
tox_env: ["py"]
4343
include:
@@ -64,6 +64,7 @@ jobs:
6464
uses: actions/setup-python@v5
6565
with:
6666
python-version: ${{ matrix.python }}
67+
allow-prereleases: true
6768

6869
- name: Install tox
6970
run: |

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Releases
44
UNRELEASED
55
----------
66

7+
* Python 3.8 (EOL) is no longer supported.
78
* `#524 <https://github.com/pytest-dev/pytest-mock/pull/524>`_: Added ``spy_return_iter`` to ``mocker.spy``, which contains a duplicate of the return value of the spied method if it is an ``Iterator``.
89

910
3.14.1 (2025-05-26)

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies = [
1515
"pytest>=6.2.5",
1616
]
1717
dynamic = ["version"]
18-
requires-python = ">=3.8"
18+
requires-python = ">=3.9"
1919
readme = "README.rst"
2020
license = {text = "MIT"}
2121
keywords = ["pytest", "mock"]
@@ -27,7 +27,6 @@ classifiers = [
2727
"Operating System :: OS Independent",
2828
"Programming Language :: Python :: 3",
2929
"Programming Language :: Python :: 3 :: Only",
30-
"Programming Language :: Python :: 3.8",
3130
"Programming Language :: Python :: 3.9",
3231
"Programming Language :: Python :: 3.10",
3332
"Programming Language :: Python :: 3.11",

src/pytest_mock/_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def get_mock_module(config):
1515
config.getini("mock_use_standalone_module")
1616
)
1717
if use_standalone_module:
18-
import mock
18+
from unittest import mock
1919

2020
_mock_module = mock
2121
else:

src/pytest_mock/plugin.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,15 @@
44
import itertools
55
import unittest.mock
66
import warnings
7+
from collections.abc import Generator
8+
from collections.abc import Iterable
9+
from collections.abc import Iterator
10+
from collections.abc import Mapping
711
from dataclasses import dataclass
812
from dataclasses import field
913
from typing import Any
1014
from typing import Callable
11-
from typing import Dict
12-
from typing import Generator
13-
from typing import Iterable
14-
from typing import Iterator
15-
from typing import List
16-
from typing import Mapping
1715
from typing import Optional
18-
from typing import Tuple
19-
from typing import Type
2016
from typing import TypeVar
2117
from typing import Union
2218
from typing import cast
@@ -53,7 +49,7 @@ class MockCache:
5349
Cache MagicMock and Patcher instances so we can undo them later.
5450
"""
5551

56-
cache: List[MockCacheItem] = field(default_factory=list)
52+
cache: list[MockCacheItem] = field(default_factory=list)
5753

5854
def _find(self, mock: MockType) -> MockCacheItem:
5955
for mock_item in self.cache:
@@ -125,7 +121,7 @@ def resetall(
125121
:param bool return_value: Reset the return_value of mocks.
126122
:param bool side_effect: Reset the side_effect of mocks.
127123
"""
128-
supports_reset_mock_with_args: Tuple[Type[Any], ...]
124+
supports_reset_mock_with_args: tuple[type[Any], ...]
129125
if hasattr(self, "AsyncMock"):
130126
supports_reset_mock_with_args = (self.Mock, self.AsyncMock)
131127
else:
@@ -348,7 +344,7 @@ def multiple(
348344
autospec: Optional[builtins.object] = None,
349345
new_callable: Optional[builtins.object] = None,
350346
**kwargs: Any,
351-
) -> Dict[str, MockType]:
347+
) -> dict[str, MockType]:
352348
"""API to mock.patch.multiple"""
353349
return self._start_patch(
354350
self.mock_module.patch.multiple,
@@ -365,7 +361,7 @@ def multiple(
365361
def dict(
366362
self,
367363
in_dict: Union[Mapping[Any, Any], str],
368-
values: Union[Mapping[Any, Any], Iterable[Tuple[Any, Any]]] = (),
364+
values: Union[Mapping[Any, Any], Iterable[tuple[Any, Any]]] = (),
369365
clear: bool = False,
370366
**kwargs: Any,
371367
) -> Any:
@@ -477,8 +473,8 @@ def _mocker(pytestconfig: Any) -> Generator[MockerFixture, None, None]:
477473
session_mocker = pytest.fixture(scope="session")(_mocker)
478474

479475

480-
_mock_module_patches = [] # type: List[Any]
481-
_mock_module_originals = {} # type: Dict[str, Any]
476+
_mock_module_patches: list[Any] = []
477+
_mock_module_originals: dict[str, Any] = {}
482478

483479

484480
def assert_wrapper(

tests/test_pytest_mock.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
import re
44
import sys
55
import warnings
6+
from collections.abc import Generator
7+
from collections.abc import Iterable
8+
from collections.abc import Iterator
69
from contextlib import contextmanager
710
from typing import Any
811
from typing import Callable
9-
from typing import Generator
10-
from typing import Iterable
11-
from typing import Iterator
12-
from typing import Tuple
13-
from typing import Type
1412
from unittest.mock import AsyncMock
1513
from unittest.mock import MagicMock
1614

@@ -102,15 +100,15 @@ def check(mocked_rm, mocked_ls):
102100
return check
103101

104102

105-
def mock_using_patch_object(mocker: MockerFixture) -> Tuple[MagicMock, MagicMock]:
103+
def mock_using_patch_object(mocker: MockerFixture) -> tuple[MagicMock, MagicMock]:
106104
return mocker.patch.object(os, "remove"), mocker.patch.object(os, "listdir")
107105

108106

109-
def mock_using_patch(mocker: MockerFixture) -> Tuple[MagicMock, MagicMock]:
107+
def mock_using_patch(mocker: MockerFixture) -> tuple[MagicMock, MagicMock]:
110108
return mocker.patch("os.remove"), mocker.patch("os.listdir")
111109

112110

113-
def mock_using_patch_multiple(mocker: MockerFixture) -> Tuple[MagicMock, MagicMock]:
111+
def mock_using_patch_multiple(mocker: MockerFixture) -> tuple[MagicMock, MagicMock]:
114112
r = mocker.patch.multiple("os", remove=mocker.DEFAULT, listdir=mocker.DEFAULT)
115113
return r["remove"], r["listdir"]
116114

@@ -212,10 +210,7 @@ def test_mocker_resetall(mocker: MockerFixture) -> None:
212210
assert isinstance(listdir.return_value, mocker.Mock)
213211
assert open.side_effect is None
214212

215-
if sys.version_info >= (3, 9):
216-
# The reset on child mocks have been implemented in 3.9
217-
# https://bugs.python.org/issue38932
218-
assert mocked_object.run.return_value != "mocked"
213+
assert mocked_object.run.return_value != "mocked"
219214

220215

221216
class TestMockerStub:
@@ -291,7 +286,7 @@ def bar(self, arg):
291286
),
292287
)
293288
def test_instance_method_spy_exception(
294-
exc_cls: Type[BaseException],
289+
exc_cls: type[BaseException],
295290
mocker: MockerFixture,
296291
) -> None:
297292
class Foo:

tox.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
[tox]
22
minversion = 3.5.3
3-
envlist = py{38,39,310,311,312,313,314}, norewrite, pytest6
3+
envlist = py{39,310,311,312,313,314}, norewrite, pytest6
44

55
[testenv]
66
deps =
77
coverage
8-
mock
98
pytest-asyncio
109
pytest6: pytest==6.2.5
1110
commands =

0 commit comments

Comments
 (0)