I shared this article for one single reason, and that is to point out one of my pet peeves: in Python, NEVER TYPE-CHECK THE TESTS. Ever.
Running static analysis on types (annotated or not; types are always present) and running (unit) tests, literally have the opposite purpose. As it says on the tin, static checks are static, i.e. they explore the code to find any potential conflicts in types that can be expected at runtime; on the other hand, unit tests are executed, and are supposed to mimic the behaviour at runtime.
It is absolutely recommended to run both, but separately -- this article in fact illustrates precisely what happens if you mix them up: you end up running in circles trying to satisfy the static analysis of the code that only matters when executed.
So simply don't bother annotating your test code, and exclude the test directories from mypy and other static checks.
Running static analysis on types (annotated or not; types are always present) and running (unit) tests, literally have the opposite purpose. As it says on the tin, static checks are static, i.e. they explore the code to find any potential conflicts in types that can be expected at runtime; on the other hand, unit tests are executed, and are supposed to mimic the behaviour at runtime.
It is absolutely recommended to run both, but separately -- this article in fact illustrates precisely what happens if you mix them up: you end up running in circles trying to satisfy the static analysis of the code that only matters when executed.
So simply don't bother annotating your test code, and exclude the test directories from mypy and other static checks.
Thank you for listening to my TED talk.