teyit
teyit copied to clipboard
Refactor `assert x == y` into `self.assertEqual(x, y)`
trafficstars
I think the second option is better because:
- It does not get removed in
-Omode - It has much cleaner error message
Are there any tests that use assert x == y in an unittest? I've never seen such code, but if you have any examples feel free to add an implementation for that.
CPython has lots of assert tests with unittest.
Examples:
- https://github.com/python/cpython/blob/main/Lib/test/test_types.py#L229-L230
- https://github.com/python/cpython/blob/main/Lib/test/test_typing.py#L4109-L4110
- https://github.com/python/cpython/blob/main/Lib/test/test_dis.py#L1432
- etc
I think that this is an error, but I would not push this change there 🙂 I will send a PR with this feature somewhere this week, though 👍
Ah, TIL. Would gladly accept a PR about it.
I think that there are some important limitations to this rule:
- It should be limited to
ast.[Async]FunctionDefscope insideast.ClassDef - We must be sure that it is a test function. For now, I am going to detect a test as "a method" with
testprefix or postfix - We must be sure that
selfargument exists