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

Invalid client tests that always pass #1684

Closed
alexrudd2 opened this issue Jul 20, 2023 · 1 comment · Fixed by #1685
Closed

Invalid client tests that always pass #1684

alexrudd2 opened this issue Jul 20, 2023 · 1 comment · Fixed by #1685

Comments

@alexrudd2
Copy link
Collaborator

alexrudd2 commented Jul 20, 2023

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.

@alexrudd2
Copy link
Collaborator Author

This was caught with a newer version of ruff. :). I will prepare a PR to upgrade it.

test/test_client_sync.py:203:16: PGH005 Non-existent mock method: `called_once_with`
test/test_client_sync.py:292:16: PGH005 Non-existent mock method: `called_once_with`

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant