A mock check such as called_once_with is written without assert_, so it checks nothing
What it finds
mock.called_once_with(1) is not an assertion: on a Mock any unknown attribute is a new mock, so the call returns another mock and the test passes whatever happened. The methods that check are named assert_called_once_with, assert_called_with, assert_not_called and so on. Reported are calls of these names without the prefix, whose result is dropped, and calls of names that start like an assertion (assert_called…, assert_awaited…) but are none of the real ones, which only Python 3.12 and later turn into errors.
From the rule's source, mock_check_without_assert.rs.
from unittest import mock def test_send(client): client.send = mock.Mock() client.send.called_once_with(1)tx0 reports: called_once_with only makes another mock; the check is assert_called_once_with client.send.assert_called_once_wiht(1)tx0 reports: assert_called_once_wiht is not a mock assertion client.send.assert_called_once_with(1) client.send.not_called()tx0 reports: the check is assert_not_called ok = client.send.called_once_with(1) Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/python:mock-check-without-assert" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:mock-check-without-assert] reason="..."tx0 explain tx0/python:mock-check-without-assert shows the same in the terminal. Found a false positive? Report it.