9
9
from typing import Generator
10
10
from typing import Tuple
11
11
from typing import Type
12
+ from unittest .mock import AsyncMock
12
13
from unittest .mock import MagicMock
13
14
14
15
import pytest
22
23
platform .python_implementation () == "PyPy" , reason = "could not make it work on pypy"
23
24
)
24
25
25
- # Python 3.8 changed the output formatting (bpo-35500), which has been ported to mock 3.0
26
- NEW_FORMATTING = sys .version_info >= (3 , 8 )
27
26
# Python 3.11.7 changed the output formatting, https://github.com/python/cpython/issues/111019
28
27
NEWEST_FORMATTING = sys .version_info >= (3 , 11 , 7 )
29
28
30
- if sys .version_info [:2 ] >= (3 , 8 ):
31
- from unittest .mock import AsyncMock
32
-
33
29
34
30
@pytest .fixture
35
31
def needs_assert_rewrite (pytestconfig ):
@@ -173,12 +169,7 @@ def test_mock_patch_dict_resetall(mocker: MockerFixture) -> None:
173
169
"NonCallableMock" ,
174
170
"PropertyMock" ,
175
171
"sentinel" ,
176
- pytest .param (
177
- "seal" ,
178
- marks = pytest .mark .skipif (
179
- sys .version_info < (3 , 7 ), reason = "seal is present on 3.7 and above"
180
- ),
181
- ),
172
+ "seal" ,
182
173
],
183
174
)
184
175
def test_mocker_aliases (name : str , pytestconfig : Any ) -> None :
@@ -243,10 +234,8 @@ def __test_failure_message(self, mocker: MockerFixture, **kwargs: Any) -> None:
243
234
expected_name = kwargs .get ("name" ) or "mock"
244
235
if NEWEST_FORMATTING :
245
236
msg = "expected call not found.\n Expected: {0}()\n Actual: not called."
246
- elif NEW_FORMATTING :
247
- msg = "expected call not found.\n Expected: {0}()\n Actual: not called."
248
237
else :
249
- msg = "Expected call: {0}()\n Not called"
238
+ msg = "expected call not found. \n Expected : {0}()\n Actual: not called. "
250
239
expected_message = msg .format (expected_name )
251
240
stub = mocker .stub (** kwargs )
252
241
with pytest .raises (AssertionError , match = re .escape (expected_message )):
@@ -259,10 +248,6 @@ def test_failure_message_with_no_name(self, mocker: MagicMock) -> None:
259
248
def test_failure_message_with_name (self , mocker : MagicMock , name : str ) -> None :
260
249
self .__test_failure_message (mocker , name = name )
261
250
262
- @pytest .mark .skipif (
263
- sys .version_info [:2 ] < (3 , 8 ),
264
- reason = "This Python version doesn't have `AsyncMock`." ,
265
- )
266
251
def test_async_stub_type (self , mocker : MockerFixture ) -> None :
267
252
assert isinstance (mocker .async_stub (), AsyncMock )
268
253
@@ -892,17 +877,11 @@ def test(mocker):
892
877
"""
893
878
)
894
879
result = testdir .runpytest ("-s" )
895
- if NEW_FORMATTING :
896
- expected_lines = [
897
- "*AssertionError: expected call not found." ,
898
- "*Expected: mock('', bar=4)" ,
899
- "*Actual: mock('fo')" ,
900
- ]
901
- else :
902
- expected_lines = [
903
- "*AssertionError: Expected call: mock('', bar=4)*" ,
904
- "*Actual call: mock('fo')*" ,
905
- ]
880
+ expected_lines = [
881
+ "*AssertionError: expected call not found." ,
882
+ "*Expected: mock('', bar=4)" ,
883
+ "*Actual: mock('fo')" ,
884
+ ]
906
885
expected_lines += [
907
886
"*pytest introspection follows:*" ,
908
887
"*Args:" ,
@@ -918,9 +897,6 @@ def test(mocker):
918
897
result .stdout .fnmatch_lines (expected_lines )
919
898
920
899
921
- @pytest .mark .skipif (
922
- sys .version_info < (3 , 8 ), reason = "AsyncMock is present on 3.8 and above"
923
- )
924
900
@pytest .mark .usefixtures ("needs_assert_rewrite" )
925
901
def test_detailed_introspection_async (testdir : Any ) -> None :
926
902
"""Check that the "mock_use_standalone" is being used."""
0 commit comments