[issue41877] Check against misspellings of assert etc. in mock
Václav Brožek added the comment: The three PRs which landed for this bug implement what I planned in the original comment, so I'm closing this bug. -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker <https://bugs.python.org/issue41877> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41877] Check against misspellings of assert etc. in mock
Václav Brožek added the comment: https://github.com/python/cpython/pull/23737 has the initial draft of the check against misspelled arguments. -- ___ Python tracker <https://bugs.python.org/issue41877> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41877] Check against misspellings of assert etc. in mock
Change by Václav Brožek : -- pull_requests: +22596 pull_request: https://github.com/python/cpython/pull/23737 ___ Python tracker <https://bugs.python.org/issue41877> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41877] Check against misspellings of assert etc. in mock
Václav Brožek added the comment: https://github.com/python/cpython/pull/23729 is now a follow-up to improve docs and error message about the assert misspellings. I'm now looking at the misspelled arguments: autospec and spec_set. These are accepted by patch, patch.object and patch.multiple, and spec_set is also accepted by create_autospec. The three frequent misspellings I saw in our codebase are auto_spec, autospect and set_spec. I could add a check to look for them in kwargs, and also add an "unsafe" argument (default False), which, when True, disables the check. This would mimic what is already done for the misspelled asserts. -- ___ Python tracker <https://bugs.python.org/issue41877> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41877] Check against misspellings of assert etc. in mock
Change by Václav Brožek : -- pull_requests: +22589 pull_request: https://github.com/python/cpython/pull/23729 ___ Python tracker <https://bugs.python.org/issue41877> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41877] Check against misspellings of assert etc. in mock
Václav Brožek added the comment: A pull request implementing the first part of this issue (Wrong prefixes of mock asserts: asert/aseert/assrt -> assert) is at https://github.com/python/cpython/pull/23165. I acknowledge that this is a controversial topic and I put forward my reasons to carry on with the above pull request in msg378569. I welcome a further discussion on the PR. -- ___ Python tracker <https://bugs.python.org/issue41877> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41877] Check against misspellings of assert etc. in mock
Change by Václav Brožek : -- keywords: +patch pull_requests: +22077 stage: -> patch review pull_request: https://github.com/python/cpython/pull/23165 ___ Python tracker <https://bugs.python.org/issue41877> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41877] Check against misspellings of assert etc. in mock
Václav Brožek added the comment: Thank you all for the informative replies (and sorry for my long silence, I was sick). I agree that the general solution (module-level assert) is worth doing, and I just added the current motivation to https://bugs.python.org/issue24651. I still think that the cost associated with bad misspellings compared to the effort to extend the existing solution (adding patterns to [1]) is strongly in favour of extending the solution: the recent clean-up we had cost us many hours of work and involved several people (especially cases with potential or real bugs being discovered after the fixed typos). Adding a pattern to [1] seems much cheaper than the cost it saves. The general solution is unlikely to be implemented soon, and even once it is, migrating existing code to use it seems unrealistic from the cost perspective. That's why I think that adding the newly found patterns to [1] makes sense. [1] https://github.com/python/cpython/blob/master/Lib/unittest/mock.py#L634 -- ___ Python tracker <https://bugs.python.org/issue41877> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24651] Mock.assert* API is in user namespace
Václav Brožek added the comment: As for the assert misspellings raising AttributeError -- that's not true of all of them, only those starting with "assret" or "assert" [1]. In my company, we recently cleaned up a bunch of other assert-misspellings, including cases where a real bug was masked in the code by that. That's why I filed https://bugs.python.org/issue41877. IMO, the fact that the assert-misspellings issue is not completely fixed seems to increase the motivation to add a module-level assert. While it's easy to add further misspellings to the check in [1], the general solution proposed in this ticket avoids a length whack-a-mole for code owners who would be able / willing to switch to a module-level assert. [1] https://github.com/python/cpython/blob/master/Lib/unittest/mock.py#L634 -- nosy: +vabr2 ___ Python tracker <https://bugs.python.org/issue24651> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41877] Check against misspellings of assert etc. in mock
New submission from Václav Brožek : Recently we cleaned up the following typos in mocks in unittests of our codebase: * Wrong prefixes of mock asserts: asert/aseert/assrt -> assert * Wrong attribute names around asserts: autospect/auto_spec -> autospec, set_spec -> spec_set Especially the asserts are dangerous, because a misspelled assert_called will fail silently. We found real bugs in production code which were masked by a misspelled assert_called. There is prior work done to report similar cases of assert misspellings with an AttributeError: https://github.com/testing-cabal/mock/commit/7c530f0d9aa48d2538501761098df7a5a8979a7d, and adding new cases will be an easy change. I suppose that adding similar error signalling for the wrong argument names will not be much harder. I'm prepared to implement it, if people of this project would be happy to have such checks. -- components: Library (Lib) messages: 377611 nosy: vabr2 priority: normal severity: normal status: open title: Check against misspellings of assert etc. in mock type: enhancement versions: Python 3.10 ___ Python tracker <https://bugs.python.org/issue41877> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com