Skip to content

Invalid client tests that always pass #1684

@alexrudd2

Description

@alexrudd2

def test_tcp_client_register(self):
"""Test tcp client."""
class CustomRequest: # pylint: disable=too-few-public-methods
"""Dummy custom request."""
function_code = 79
client = ModbusTcpClient("127.0.0.1")
client.framer = mock.Mock()
client.register(CustomRequest)
assert client.framer.decoder.register.called_once_with(CustomRequest)

def test_tls_client_register(self):
"""Test tls client."""
class CustomeRequest: # pylint: disable=too-few-public-methods
"""Dummy custom request."""
function_code = 79
client = ModbusTlsClient("127.0.0.1")
client.framer = mock.Mock()
client.register(CustomeRequest)
assert client.framer.decoder.register.called_once_with(CustomeRequest)

These tests will always pass. even if the call were changed to client.register('WTFBBQ'), client.register(NotImplementedError), or anything else.

(1) mock.called_once_with() does not exist. It should be mock.assert_called_once_with().
(2) The assert at the beginning of the line will pass on any truth-y value, including a mocked method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions