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

Test failure with Python 3.12 #147

Closed
fabaff opened this issue Jan 23, 2024 · 1 comment
Closed

Test failure with Python 3.12 #147

fabaff opened this issue Jan 23, 2024 · 1 comment

Comments

@fabaff
Copy link
Contributor

fabaff commented Jan 23, 2024

There is a failure with Python 3.12. The test passes on Python < 3.12.

============================= test session starts ==============================
platform linux -- Python 3.12.1, pytest-7.4.3, pluggy-1.3.0
rootdir: /build/source
collected 59 items                                                             

test/test_filereader.py .                                                [  1%]
[...]
test/test_parse_v5_eon_hungary.py ....                                   [ 54%]
test/test_protocol.py .F                                                 [ 57%]
test/test_rfxtrx_protocol.py .                                           [ 59%]
test/test_telegram_buffer.py .........                                   [ 74%]
test/objects/test_mbusdevice.py ...                                      [ 79%]
test/objects/test_parser_corner_cases.py ....                            [ 86%]
test/objects/test_telegram.py ........                                   [100%]

=================================== FAILURES ===================================
_______________________ ProtocolTest.test_receive_packet _______________________

self = <test.test_protocol.ProtocolTest testMethod=test_receive_packet>

    def test_receive_packet(self):
        """Protocol packet reception."""
    
        mock_transport = Mock()
        self.protocol.connection_made(mock_transport)
        assert not self.protocol._active
    
        self.protocol.data_received(TELEGRAM_V2_2.encode('ascii'))
        assert self.protocol._active
    
        # 1st call of keep_alive resets 'active' flag
        self.protocol.keep_alive()
        assert not self.protocol._active
    
        # 2nd call of keep_alive should close the transport
        self.protocol.keep_alive()
>       assert mock_transport.close.called_once()

test/test_protocol.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Mock name='mock.close' id='140737310204912'>, name = 'called_once'

    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' is not a valid assertion. Use a spec for the mock if 'called_once' is meant to be an attribute.

/nix/store/r2pbmhh7l7g6f3avk8vg8d33frl4c2sx-python3-3.12.1/lib/python3.12/unittest/mock.py:663: AttributeError
------------------------------ Captured log call -------------------------------
WARNING  dsmr_parser.clients.protocol:protocol.py:142 keep-alive check failed
=============================== warnings summary ===============================
../../nix/store/jl22rhi9ch8qci1ssjvwrfw9asajbbpa-python3.12-python-dateutil-2.8.2/lib/python3.12/site-packages/dateutil/tz/tz.py:37
  /nix/store/jl22rhi9ch8qci1ssjvwrfw9asajbbpa-python3.12-python-dateutil-2.8.2/lib/python3.12/site-packages/dateutil/tz/tz.py:37: 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).
    EPOCH = datetime.datetime.utcfromtimestamp(0)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED test/test_protocol.py::ProtocolTest::test_receive_packet - AttributeError: 'called_once' is not a valid assertion. Use a spec for the ...
=================== 1 failed, 58 passed, 1 warning in 0.60s ====================
/nix/store/v5irq7wvkr7kih0hhnch5nnv2dcq8c4f-stdenv-linux/setup: line 1557: pop_var_context: head of shell_variables not a function context
error: builder for '/nix/store/wzafawdgiz41173yrw48a6kkpz3pcdd0-python3.12-dsmr-parser-1.3.1.drv' failed with exit code 1;
       last 10 log lines:
       > =============================== warnings summary ===============================
       > ../../nix/store/jl22rhi9ch8qci1ssjvwrfw9asajbbpa-python3.12-python-dateutil-2.8.2/lib/python3.12/site-packages/dateutil/tz/tz.py:37
       >   /nix/store/jl22rhi9ch8qci1ssjvwrfw9asajbbpa-python3.12-python-dateutil-2.8.2/lib/python3.12/site-packages/dateutil/tz/tz.py:37: 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).
       >     EPOCH = datetime.datetime.utcfromtimestamp(0)
       >
       > -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
       > =========================== short test summary info ============================
       > FAILED test/test_protocol.py::ProtocolTest::test_receive_packet - AttributeError: 'called_once' is not a valid assertion. Use a spec for the ...
       > =================== 1 failed, 58 passed, 1 warning in 0.60s ====================
@ndokter
Copy link
Owner

ndokter commented Jan 29, 2024

Thanks for creating the issue. I have made a fix and released it as v1.3.2

@ndokter ndokter closed this as completed Jan 29, 2024
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