99from typing import Generator
1010from typing import Tuple
1111from typing import Type
12+ from unittest .mock import AsyncMock
1213from unittest .mock import MagicMock
1314
1415import pytest
2223 platform .python_implementation () == "PyPy" , reason = "could not make it work on pypy"
2324)
2425
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 )
2726# Python 3.11.7 changed the output formatting, https://github.com/python/cpython/issues/111019
2827NEWEST_FORMATTING = sys .version_info >= (3 , 11 , 7 )
2928
30- if sys .version_info [:2 ] >= (3 , 8 ):
31- from unittest .mock import AsyncMock
32-
3329
3430@pytest .fixture
3531def needs_assert_rewrite (pytestconfig ):
@@ -173,12 +169,7 @@ def test_mock_patch_dict_resetall(mocker: MockerFixture) -> None:
173169 "NonCallableMock" ,
174170 "PropertyMock" ,
175171 "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" ,
182173 ],
183174)
184175def test_mocker_aliases (name : str , pytestconfig : Any ) -> None :
@@ -243,10 +234,8 @@ def __test_failure_message(self, mocker: MockerFixture, **kwargs: Any) -> None:
243234 expected_name = kwargs .get ("name" ) or "mock"
244235 if NEWEST_FORMATTING :
245236 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."
248237 else :
249- msg = "Expected call: {0}()\n Not called"
238+ msg = "expected call not found. \n Expected : {0}()\n Actual: not called. "
250239 expected_message = msg .format (expected_name )
251240 stub = mocker .stub (** kwargs )
252241 with pytest .raises (AssertionError , match = re .escape (expected_message )):
@@ -259,10 +248,6 @@ def test_failure_message_with_no_name(self, mocker: MagicMock) -> None:
259248 def test_failure_message_with_name (self , mocker : MagicMock , name : str ) -> None :
260249 self .__test_failure_message (mocker , name = name )
261250
262- @pytest .mark .skipif (
263- sys .version_info [:2 ] < (3 , 8 ),
264- reason = "This Python version doesn't have `AsyncMock`." ,
265- )
266251 def test_async_stub_type (self , mocker : MockerFixture ) -> None :
267252 assert isinstance (mocker .async_stub (), AsyncMock )
268253
@@ -892,17 +877,11 @@ def test(mocker):
892877 """
893878 )
894879 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+ ]
906885 expected_lines += [
907886 "*pytest introspection follows:*" ,
908887 "*Args:" ,
@@ -918,9 +897,6 @@ def test(mocker):
918897 result .stdout .fnmatch_lines (expected_lines )
919898
920899
921- @pytest .mark .skipif (
922- sys .version_info < (3 , 8 ), reason = "AsyncMock is present on 3.8 and above"
923- )
924900@pytest .mark .usefixtures ("needs_assert_rewrite" )
925901def test_detailed_introspection_async (testdir : Any ) -> None :
926902 """Check that the "mock_use_standalone" is being used."""
0 commit comments