isidentical / teyit

Formatter for your Python unit tests
MIT License
104 stars 7 forks source link

Refactor `assert x == y` into `self.assertEqual(x, y)` #12

Open sobolevn opened 2 years ago

sobolevn commented 2 years ago

I think the second option is better because:

  1. It does not get removed in -O mode
  2. It has much cleaner error message
isidentical commented 2 years ago

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.

sobolevn commented 2 years ago

CPython has lots of assert tests with unittest. Examples:

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 👍

isidentical commented 2 years ago

Ah, TIL. Would gladly accept a PR about it.

sobolevn commented 2 years ago

I think that there are some important limitations to this rule:

  1. It should be limited to ast.[Async]FunctionDef scope inside ast.ClassDef
  2. We must be sure that it is a test function. For now, I am going to detect a test as "a method" with test prefix or postfix
  3. We must be sure that self argument exists