When working on #3317, I would have liked to be able to run pyright/ty/pyrefly on some yaml test case we have because some feature that previously required mypy plugin now should work with builtin python typing constructs. There are also preliminary support for django feature added in pyrefly for ex that we could test here.
So I was wondering how we could handle typechecking tests in tests/typecheck against more typechecker.
Current state
We currently use:
pytest-mypy-plugins for tests in tests/typecheck but it only support mypy currently.
assert_type tests in tests/assert_type running against mypy / pyright / pyrefly & ty
We already migrated some tests to assert_type when they don't required mypy plugin to extand coverage but it get's a bit more complicated once we touch django models.
Migration options
I think it would be nice to gradually move some tests from tests/typecheck to assert_type to get more coverage but there are still some usefull feature in pytest-mypy-plugins that we might lose along the way.
- registration of models for django via installed_apps
- assertion of detailed error output
- custom django settings
There are a few directions I see and would like to gather feedback and ideas to solve this:
- Migrate to
assert_type.
- We would need a directory structure convention to register models. We can take inspiration from django own test suite that does that with a bunch of
submodules automatically registered as django apps by the test runner.
- We would lose precise error message assertion
- Extend
pytest-mypy-plugins with multi-checker backends
- I suspect this would be a huge effort because the package was designed with only mypy in mind
- We would have to find a way to assert error messages from other typecheckers too
pytest-typing
- Similar to the
assert_type test we have but a bit easier to digest maybe, it's inspired from ty typing test framework
- Allows asserting exact error messages too
- Another idea ?
I tried a small poc for the Migrate to assert_type option by migrating ŧest_base.yml, it mostly work but we do loose the exact error assertions
What do you guys think ? Any idea on how to make this easier ?
When working on #3317, I would have liked to be able to run pyright/ty/pyrefly on some yaml test case we have because some feature that previously required mypy plugin now should work with builtin python typing constructs. There are also preliminary support for django feature added in pyrefly for ex that we could test here.
So I was wondering how we could handle typechecking tests in
tests/typecheckagainst more typechecker.Current state
We currently use:
pytest-mypy-pluginsfor tests intests/typecheckbut it only support mypy currently.assert_typetests intests/assert_typerunning against mypy / pyright / pyrefly & tyWe already migrated some tests to
assert_typewhen they don't required mypy plugin to extand coverage but it get's a bit more complicated once we touch django models.Migration options
I think it would be nice to gradually move some tests from
tests/typechecktoassert_typeto get more coverage but there are still some usefull feature inpytest-mypy-pluginsthat we might lose along the way.There are a few directions I see and would like to gather feedback and ideas to solve this:
assert_type.submodulesautomatically registered as django apps by the test runner.pytest-mypy-pluginswith multi-checker backendspytest-typingassert_typetest we have but a bit easier to digest maybe, it's inspired fromtytyping test frameworkI tried a small poc for the
Migrate to assert_typeoption by migratingŧest_base.yml, it mostly work but we do loose the exact error assertionsWhat do you guys think ? Any idea on how to make this easier ?