Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Python 3.12, AttributeError: 'called_once_with' is not a valid assertion #1265

Closed
musicinmybrain opened this issue Oct 29, 2023 · 3 comments

Comments

@musicinmybrain
Copy link
Contributor

Describe the bug

The following tests fail with AttributeError: 'called_once_with' is not a valid assertion on Python 3.12. This is a new regression from 5.9.0 to 5.10.0.

FAILED tests/async/test_simple_client.py::TestAsyncAsyncSimpleClient::test_call
FAILED tests/async/test_simple_client.py::TestAsyncAsyncSimpleClient::test_connect
FAILED tests/async/test_simple_client.py::TestAsyncAsyncSimpleClient::test_connect_context_manager
FAILED tests/async/test_simple_client.py::TestAsyncAsyncSimpleClient::test_emit
FAILED tests/common/test_simple_client.py::TestSimpleClient::test_call - Attr...
FAILED tests/common/test_simple_client.py::TestSimpleClient::test_connect - A...
FAILED tests/common/test_simple_client.py::TestSimpleClient::test_connect_context_manager
FAILED tests/common/test_simple_client.py::TestSimpleClient::test_emit - Attr...

To Reproduce
Steps to reproduce the behavior:

python3.12 -m venv _e
. _e/bin/activate
pip install aiohttp==3.9.0b0
pip install -e .[client,asyncio_client]
pip install uvicorn msgpack pytest pytest-timeout pytest-cov
pytest -p no:logging --timeout=60

Expected behavior

All tests pass.

Logs

================================================ test session starts =================================================
platform linux -- Python 3.12.0, pytest-7.4.3, pluggy-1.3.0
rootdir: /home/ben/src/forks/python-socketio
plugins: timeout-2.2.0, cov-4.1.0
timeout: 60.0s
timeout method: signal
timeout func_only: False
collected 570 items                                                                                                  

tests/async/test_admin.py ..........                                                                           [  1%]
tests/async/test_client.py .......................................................................             [ 14%]
tests/async/test_manager.py ..............................                                                     [ 19%]
tests/async/test_namespace.py .....................                                                            [ 23%]
tests/async/test_pubsub_manager.py ..................................                                          [ 29%]
tests/async/test_server.py .........................................................................           [ 41%]
tests/async/test_simple_client.py F..FF...F.......                                                             [ 44%]
tests/common/test_admin.py .........                                                                           [ 46%]
tests/common/test_client.py .................................................................................. [ 60%]
..                                                                                                             [ 61%]
tests/common/test_manager.py ...............................                                                   [ 66%]
tests/common/test_middleware.py ...                                                                            [ 67%]
tests/common/test_msgpack_packet.py ....                                                                       [ 67%]
tests/common/test_namespace.py ..................                                                              [ 70%]
tests/common/test_packet.py ......................................                                             [ 77%]
tests/common/test_pubsub_manager.py ....................................                                       [ 83%]
tests/common/test_server.py ............................................................................       [ 97%]
tests/common/test_simple_client.py F..FF...F.......                                                            [100%]

====================================================== FAILURES ======================================================
________________________________________ TestAsyncAsyncSimpleClient.test_call ________________________________________

self = <tests.async.test_simple_client.TestAsyncAsyncSimpleClient testMethod=test_call>

    def test_call(self):
        client = AsyncSimpleClient()
        client.client = mock.MagicMock()
        client.client.call = AsyncMock()
        client.client.call.mock.return_value = 'result'
        client.namespace = '/ns'
        client.connected_event.set()
        client.connected = True
    
        assert _run(client.call('foo', 'bar')) == 'result'
        assert client.client.call.mock.called_once_with('foo', 'bar',
                                                        namespace='/ns',
>                                                       timeout=60)

tests/async/test_simple_client.py:121: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <MagicMock name='mock.call' id='140113382154768'>, name = 'called_once_with'

    def __getattr__(self, name):
        if name in {'_mock_methods', '_mock_unsafe'}:
            raise AttributeError(name)
        elif self._mock_methods is not None:
            if name not in self._mock_methods or name in _all_magics:
                raise AttributeError("Mock object has no attribute %r" % name)
        elif _is_magic(name):
            raise AttributeError(name)
        if not self._mock_unsafe and (not self._mock_methods or name not in self._mock_methods):
            if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in _ATTRIB_DENY_LIST:
>               raise AttributeError(
                    f"{name!r} is not a valid assertion. Use a spec "
                    f"for the mock if {name!r} is meant to be an attribute.")
E               AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?

/usr/lib64/python3.12/unittest/mock.py:663: AttributeError
______________________________________ TestAsyncAsyncSimpleClient.test_connect _______________________________________

self = <tests.async.test_simple_client.TestAsyncAsyncSimpleClient testMethod=test_connect>

    def test_connect(self):
        client = AsyncSimpleClient(123, a='b')
        with mock.patch('socketio.async_simple_client.AsyncClient') \
                as mock_client:
            mock_client.return_value.connect = AsyncMock()
    
            _run(client.connect('url', headers='h', auth='a', transports='t',
                                namespace='n', socketio_path='s',
                                wait_timeout='w'))
            mock_client.assert_called_once_with(123, a='b')
            assert client.client == mock_client()
            mock_client().connect.mock.assert_called_once_with(
                'url', headers='h', auth='a', transports='t',
                namespaces=['n'], socketio_path='s', wait_timeout='w')
            mock_client().event.call_count == 3
>           mock_client().on.called_once_with('*')

tests/async/test_simple_client.py:35: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <MagicMock name='AsyncClient().on' id='140113381006832'>, name = 'called_once_with'

    def __getattr__(self, name):
        if name in {'_mock_methods', '_mock_unsafe'}:
            raise AttributeError(name)
        elif self._mock_methods is not None:
            if name not in self._mock_methods or name in _all_magics:
                raise AttributeError("Mock object has no attribute %r" % name)
        elif _is_magic(name):
            raise AttributeError(name)
        if not self._mock_unsafe and (not self._mock_methods or name not in self._mock_methods):
            if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in _ATTRIB_DENY_LIST:
>               raise AttributeError(
                    f"{name!r} is not a valid assertion. Use a spec "
                    f"for the mock if {name!r} is meant to be an attribute.")
E               AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?

/usr/lib64/python3.12/unittest/mock.py:663: AttributeError
______________________________ TestAsyncAsyncSimpleClient.test_connect_context_manager _______________________________

self = <tests.async.test_simple_client.TestAsyncAsyncSimpleClient testMethod=test_connect_context_manager>

    def test_connect_context_manager(self):
        async def _t():
            async with AsyncSimpleClient(123, a='b') as client:
                with mock.patch('socketio.async_simple_client.AsyncClient') \
                        as mock_client:
                    mock_client.return_value.connect = AsyncMock()
    
                    await client.connect('url', headers='h', auth='a',
                                         transports='t', namespace='n',
                                         socketio_path='s', wait_timeout='w')
                    mock_client.assert_called_once_with(123, a='b')
                    assert client.client == mock_client()
                    mock_client().connect.mock.assert_called_once_with(
                        'url', headers='h', auth='a', transports='t',
                        namespaces=['n'], socketio_path='s', wait_timeout='w')
                    mock_client().event.call_count == 3
                    mock_client().on.called_once_with('*')
                    assert client.namespace == 'n'
                    assert not client.input_event.is_set()
    
>       _run(_t())

tests/async/test_simple_client.py:59: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/async/helpers.py:18: in _run
    return asyncio.get_event_loop().run_until_complete(coro)
/usr/lib64/python3.12/asyncio/base_events.py:664: in run_until_complete
    return future.result()
tests/async/test_simple_client.py:55: in _t
    mock_client().on.called_once_with('*')
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <MagicMock name='AsyncClient().on' id='140113377284160'>, name = 'called_once_with'

    def __getattr__(self, name):
        if name in {'_mock_methods', '_mock_unsafe'}:
            raise AttributeError(name)
        elif self._mock_methods is not None:
            if name not in self._mock_methods or name in _all_magics:
                raise AttributeError("Mock object has no attribute %r" % name)
        elif _is_magic(name):
            raise AttributeError(name)
        if not self._mock_unsafe and (not self._mock_methods or name not in self._mock_methods):
            if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in _ATTRIB_DENY_LIST:
>               raise AttributeError(
                    f"{name!r} is not a valid assertion. Use a spec "
                    f"for the mock if {name!r} is meant to be an attribute.")
E               AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?

/usr/lib64/python3.12/unittest/mock.py:663: AttributeError
________________________________________ TestAsyncAsyncSimpleClient.test_emit ________________________________________

self = <tests.async.test_simple_client.TestAsyncAsyncSimpleClient testMethod=test_emit>

    def test_emit(self):
        client = AsyncSimpleClient()
        client.client = mock.MagicMock()
        client.client.emit = AsyncMock()
        client.namespace = '/ns'
        client.connected_event.set()
        client.connected = True
    
        _run(client.emit('foo', 'bar'))
        assert client.client.emit.mock.called_once_with('foo', 'bar',
>                                                       namespace='/ns')

tests/async/test_simple_client.py:89: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <MagicMock name='mock.emit' id='140113377238800'>, name = 'called_once_with'

    def __getattr__(self, name):
        if name in {'_mock_methods', '_mock_unsafe'}:
            raise AttributeError(name)
        elif self._mock_methods is not None:
            if name not in self._mock_methods or name in _all_magics:
                raise AttributeError("Mock object has no attribute %r" % name)
        elif _is_magic(name):
            raise AttributeError(name)
        if not self._mock_unsafe and (not self._mock_methods or name not in self._mock_methods):
            if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in _ATTRIB_DENY_LIST:
>               raise AttributeError(
                    f"{name!r} is not a valid assertion. Use a spec "
                    f"for the mock if {name!r} is meant to be an attribute.")
E               AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?

/usr/lib64/python3.12/unittest/mock.py:663: AttributeError
_____________________________________________ TestSimpleClient.test_call _____________________________________________

self = <tests.common.test_simple_client.TestSimpleClient testMethod=test_call>

    def test_call(self):
        client = SimpleClient()
        client.client = mock.MagicMock()
        client.client.call.return_value = 'result'
        client.namespace = '/ns'
        client.connected_event.set()
        client.connected = True
    
        assert client.call('foo', 'bar') == 'result'
>       client.client.call.called_once_with('foo', 'bar', namespace='/ns',
                                            timeout=60)

tests/common/test_simple_client.py:103: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <MagicMock name='mock.call' id='140113376430608'>, name = 'called_once_with'

    def __getattr__(self, name):
        if name in {'_mock_methods', '_mock_unsafe'}:
            raise AttributeError(name)
        elif self._mock_methods is not None:
            if name not in self._mock_methods or name in _all_magics:
                raise AttributeError("Mock object has no attribute %r" % name)
        elif _is_magic(name):
            raise AttributeError(name)
        if not self._mock_unsafe and (not self._mock_methods or name not in self._mock_methods):
            if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in _ATTRIB_DENY_LIST:
>               raise AttributeError(
                    f"{name!r} is not a valid assertion. Use a spec "
                    f"for the mock if {name!r} is meant to be an attribute.")
E               AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?

/usr/lib64/python3.12/unittest/mock.py:663: AttributeError
___________________________________________ TestSimpleClient.test_connect ____________________________________________

self = <tests.common.test_simple_client.TestSimpleClient testMethod=test_connect>

    def test_connect(self):
        client = SimpleClient(123, a='b')
        with mock.patch('socketio.simple_client.Client') as mock_client:
            client.connect('url', headers='h', auth='a', transports='t',
                           namespace='n', socketio_path='s', wait_timeout='w')
            mock_client.assert_called_once_with(123, a='b')
            assert client.client == mock_client()
            mock_client().connect.assert_called_once_with(
                'url', headers='h', auth='a', transports='t',
                namespaces=['n'], socketio_path='s', wait_timeout='w')
            mock_client().event.call_count == 3
>           mock_client().on.called_once_with('*')

tests/common/test_simple_client.py:28: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <MagicMock name='Client().on' id='140113377826560'>, name = 'called_once_with'

    def __getattr__(self, name):
        if name in {'_mock_methods', '_mock_unsafe'}:
            raise AttributeError(name)
        elif self._mock_methods is not None:
            if name not in self._mock_methods or name in _all_magics:
                raise AttributeError("Mock object has no attribute %r" % name)
        elif _is_magic(name):
            raise AttributeError(name)
        if not self._mock_unsafe and (not self._mock_methods or name not in self._mock_methods):
            if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in _ATTRIB_DENY_LIST:
>               raise AttributeError(
                    f"{name!r} is not a valid assertion. Use a spec "
                    f"for the mock if {name!r} is meant to be an attribute.")
E               AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?

/usr/lib64/python3.12/unittest/mock.py:663: AttributeError
___________________________________ TestSimpleClient.test_connect_context_manager ____________________________________

self = <tests.common.test_simple_client.TestSimpleClient testMethod=test_connect_context_manager>

    def test_connect_context_manager(self):
        with SimpleClient(123, a='b') as client:
            with mock.patch('socketio.simple_client.Client') as mock_client:
                client.connect('url', headers='h', auth='a', transports='t',
                               namespace='n', socketio_path='s',
                               wait_timeout='w')
                mock_client.assert_called_once_with(123, a='b')
                assert client.client == mock_client()
                mock_client().connect.assert_called_once_with(
                    'url', headers='h', auth='a', transports='t',
                    namespaces=['n'], socketio_path='s', wait_timeout='w')
                mock_client().event.call_count == 3
>               mock_client().on.called_once_with('*')

tests/common/test_simple_client.py:44: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <MagicMock name='Client().on' id='140113380087360'>, name = 'called_once_with'

    def __getattr__(self, name):
        if name in {'_mock_methods', '_mock_unsafe'}:
            raise AttributeError(name)
        elif self._mock_methods is not None:
            if name not in self._mock_methods or name in _all_magics:
                raise AttributeError("Mock object has no attribute %r" % name)
        elif _is_magic(name):
            raise AttributeError(name)
        if not self._mock_unsafe and (not self._mock_methods or name not in self._mock_methods):
            if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in _ATTRIB_DENY_LIST:
>               raise AttributeError(
                    f"{name!r} is not a valid assertion. Use a spec "
                    f"for the mock if {name!r} is meant to be an attribute.")
E               AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?

/usr/lib64/python3.12/unittest/mock.py:663: AttributeError
_____________________________________________ TestSimpleClient.test_emit _____________________________________________

self = <tests.common.test_simple_client.TestSimpleClient testMethod=test_emit>

    def test_emit(self):
        client = SimpleClient()
        client.client = mock.MagicMock()
        client.namespace = '/ns'
        client.connected_event.set()
        client.connected = True
    
        client.emit('foo', 'bar')
        assert client.client.emit.called_once_with('foo', 'bar',
>                                                  namespace='/ns')

tests/common/test_simple_client.py:75: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <MagicMock name='mock.emit' id='140113379490176'>, name = 'called_once_with'

    def __getattr__(self, name):
        if name in {'_mock_methods', '_mock_unsafe'}:
            raise AttributeError(name)
        elif self._mock_methods is not None:
            if name not in self._mock_methods or name in _all_magics:
                raise AttributeError("Mock object has no attribute %r" % name)
        elif _is_magic(name):
            raise AttributeError(name)
        if not self._mock_unsafe and (not self._mock_methods or name not in self._mock_methods):
            if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in _ATTRIB_DENY_LIST:
>               raise AttributeError(
                    f"{name!r} is not a valid assertion. Use a spec "
                    f"for the mock if {name!r} is meant to be an attribute.")
E               AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?

/usr/lib64/python3.12/unittest/mock.py:663: AttributeError
================================================== warnings summary ==================================================
tests/async/test_admin.py: 25 warnings
  /home/ben/src/forks/python-socketio/src/socketio/async_admin.py:240: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    datetime.utcnow().isoformat() + 'Z',

tests/async/test_admin.py: 34 warnings
  /home/ben/src/forks/python-socketio/src/socketio/async_admin.py:394: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    'time': datetime.utcfromtimestamp(tm).isoformat() + 'Z'

tests/async/test_admin.py: 23 warnings
  /home/ben/src/forks/python-socketio/src/socketio/async_admin.py:203: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    datetime.utcfromtimestamp(t).isoformat() + 'Z',

tests/async/test_admin.py: 23 warnings
  /home/ben/src/forks/python-socketio/src/socketio/async_admin.py:213: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    datetime.utcnow().isoformat() + 'Z',

tests/async/test_admin.py: 26 warnings
  /home/ben/src/forks/python-socketio/src/socketio/async_admin.py:250: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    datetime.utcnow().isoformat() + 'Z',

tests/async/test_admin.py::TestAsyncAdmin::test_admin_connect_with_others
tests/async/test_admin.py::TestAsyncAdmin::test_admin_features
tests/async/test_admin.py::TestAsyncAdmin::test_admin_features
tests/async/test_admin.py::TestAsyncAdmin::test_admin_features
tests/async/test_admin.py::TestAsyncAdmin::test_admin_features
tests/async/test_admin.py::TestAsyncAdmin::test_admin_features
tests/async/test_admin.py::TestAsyncAdmin::test_admin_features
  /home/ben/src/forks/python-socketio/src/socketio/async_admin.py:282: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    datetime.utcnow().isoformat() + 'Z',

tests/async/test_admin.py::TestAsyncAdmin::test_admin_features
tests/async/test_admin.py::TestAsyncAdmin::test_admin_features
tests/async/test_admin.py::TestAsyncAdmin::test_admin_features
  /home/ben/src/forks/python-socketio/src/socketio/async_admin.py:270: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    datetime.utcnow().isoformat() + 'Z',

tests/async/test_client.py::TestAsyncClient::test_call
  /home/ben/src/forks/python-socketio/tests/async/helpers.py:18: DeprecationWarning: There is no current event loop
    return asyncio.get_event_loop().run_until_complete(coro)

tests/async/test_client.py::TestAsyncClient::test_handle_reconnect_max_attempts
tests/async/test_client.py::TestAsyncClient::test_handle_reconnect_max_delay
  /usr/lib64/python3.12/unittest/mock.py:2185: RuntimeWarning: coroutine 'Event.wait' was never awaited
    def __init__(self, name, parent):
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

tests/async/test_client.py::TestAsyncClient::test_send_packet
  /usr/lib64/python3.12/unittest/mock.py:767: RuntimeWarning: coroutine 'Event.wait' was never awaited
    def __setattr__(self, name, value):
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

tests/async/test_manager.py::TestAsyncManager::test_close_invalid_room
  /home/ben/src/forks/python-socketio/tests/async/test_manager.py:195: RuntimeWarning: coroutine 'AsyncManager.close_room' was never awaited
    self.bm.close_room('bar', '/foo')
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

tests/async/test_manager.py::TestAsyncManager::test_close_room
  /usr/lib64/python3.12/unittest/mock.py:2185: RuntimeWarning: coroutine 'TestAsyncClient.test_wait_reconnect_successful.<locals>.fake_wait' was never awaited
    def __init__(self, name, parent):
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

tests/async/test_manager.py::TestAsyncManager::test_disconnect_all
  /home/ben/src/forks/python-socketio/_e/lib64/python3.12/site-packages/bidict/_base.py:460: RuntimeWarning: coroutine 'Event.wait' was never awaited
    writeop()
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

tests/common/test_admin.py: 22 warnings
  /home/ben/src/forks/python-socketio/src/socketio/admin.py:251: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    datetime.utcnow().isoformat() + 'Z',

tests/common/test_admin.py: 31 warnings
  /home/ben/src/forks/python-socketio/src/socketio/admin.py:401: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    'time': datetime.utcfromtimestamp(tm).isoformat() + 'Z'

tests/common/test_admin.py: 20 warnings
  /home/ben/src/forks/python-socketio/src/socketio/admin.py:215: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    datetime.utcfromtimestamp(t).isoformat() + 'Z',

tests/common/test_admin.py: 20 warnings
  /home/ben/src/forks/python-socketio/src/socketio/admin.py:225: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    datetime.utcnow().isoformat() + 'Z',

tests/common/test_admin.py: 23 warnings
  /home/ben/src/forks/python-socketio/src/socketio/admin.py:261: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    datetime.utcnow().isoformat() + 'Z',

tests/common/test_admin.py::TestAdmin::test_admin_connect_with_others
tests/common/test_admin.py::TestAdmin::test_admin_features
tests/common/test_admin.py::TestAdmin::test_admin_features
tests/common/test_admin.py::TestAdmin::test_admin_features
tests/common/test_admin.py::TestAdmin::test_admin_features
tests/common/test_admin.py::TestAdmin::test_admin_features
tests/common/test_admin.py::TestAdmin::test_admin_features
  /home/ben/src/forks/python-socketio/src/socketio/admin.py:293: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    datetime.utcnow().isoformat() + 'Z',

tests/common/test_admin.py::TestAdmin::test_admin_features
tests/common/test_admin.py::TestAdmin::test_admin_features
tests/common/test_admin.py::TestAdmin::test_admin_features
  /home/ben/src/forks/python-socketio/src/socketio/admin.py:281: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    datetime.utcnow().isoformat() + 'Z',

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================== short test summary info ===============================================
FAILED tests/async/test_simple_client.py::TestAsyncAsyncSimpleClient::test_call - AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is mea...
FAILED tests/async/test_simple_client.py::TestAsyncAsyncSimpleClient::test_connect - AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is mea...
FAILED tests/async/test_simple_client.py::TestAsyncAsyncSimpleClient::test_connect_context_manager - AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is mea...
FAILED tests/async/test_simple_client.py::TestAsyncAsyncSimpleClient::test_emit - AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is mea...
FAILED tests/common/test_simple_client.py::TestSimpleClient::test_call - AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is mea...
FAILED tests/common/test_simple_client.py::TestSimpleClient::test_connect - AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is mea...
FAILED tests/common/test_simple_client.py::TestSimpleClient::test_connect_context_manager - AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is mea...
FAILED tests/common/test_simple_client.py::TestSimpleClient::test_emit - AttributeError: 'called_once_with' is not a valid assertion. Use a spec for the mock if 'called_once_with' is mea...
============================== 8 failed, 562 passed, 274 warnings in 189.83s (0:03:09) ===============================

Additional context

Discovered while trying to update the python-socketio package in Fedora Linux.

@musicinmybrain
Copy link
Contributor Author

Possibly related: python/cpython#100690

@miguelgrinberg
Copy link
Owner

Thanks, and good catch. I introduced a typo here, instead of assert_called_once_with I used called_once_with, which only in 3.12 is flagged as an error. If you could, give the main branch with the fix a try and let me know if everything is good now.

I have not added 3.12 to the regular builds yet because the aiohttp package currently fails to install on that version of Python (aio-libs/aiohttp#7639). Once they have a release with support I'll start running 3.12 builds here.

@musicinmybrain
Copy link
Contributor Author

Thanks, and good catch. I introduced a typo here, instead of assert_called_once_with I used called_once_with, which only in 3.12 is flagged as an error. If you could, give the main branch with the fix a try and let me know if everything is good now.

66b9586 works for me! Thanks for the quick fix.

I have not added 3.12 to the regular builds yet because the aiohttp package currently fails to install on that version of Python (aio-libs/aiohttp#7639). Once they have a release with support I'll start running 3.12 builds here.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants