-
-
Couldn't load subscription status.
- Fork 131
Convert simpler tests to assert_type() tests
#854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
381da44 to
35ddf78
Compare
61baa73 to
5db5e09
Compare
|
|
||
| [tool.ruff.lint.flake8-tidy-imports.banned-api] | ||
| "_typeshed.Self".msg = "Use typing_extensions.Self (PEP 673) instead." | ||
| "typing.assert_type".msg = "Use typing_extensions.assert_type instead." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still typecheck with Python 3.10, which doesn't have typing.assert_type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR converts simpler typecheck tests from pytest-mypy-plugins .yml format to regular Python files using assert_type(). The conversion maintains test coverage while improving test performance, maintainability, and developer experience through IDE support and autoformatting.
Key changes:
- Migrated 50+ test cases from
.ymlfiles to.pyfiles usingassert_type() - Retained complex tests (multi-file, error message validation, parameterized) in
.ymlformat - Added mypy validation of test files to CI workflow
Reviewed Changes
Copilot reviewed 27 out of 28 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/typecheck/test_views.yml | Removed 5 simple test cases (e.g., request types, generics) |
| tests/typecheck/test_test.yml | Removed entire file containing client API test cases |
| tests/typecheck/test_serializers.yml | Removed 10 test cases for serializer functionality |
| tests/typecheck/test_routers.yml | Removed entire file containing router URL tests |
| tests/typecheck/test_request.yml | Removed entire file containing request querydict tests |
| tests/typecheck/test_pagination.yml | Removed entire file containing pagination tests |
| tests/typecheck/test_mixins.yml | Removed entire file containing mixin tests |
| tests/typecheck/test_filters.yml | Removed entire file containing filter backend tests |
| tests/typecheck/test_fields.yml | Removed 2 test cases for field functionality |
| tests/typecheck/test_exceptions.yml | Removed 3 test cases for exception declarations |
| tests/typecheck/test_decorators.yml | Removed 4 test cases, kept error validation tests |
| tests/typecheck/test_compat.yml | Removed entire file containing compatibility tests |
| tests/typecheck/test_api_client.yml | Removed entire file containing API client tests |
| tests/assert_type/views.py | Added converted view-related tests |
| tests/assert_type/test.py | Added converted test client tests |
| tests/assert_type/serializers.py | Added converted serializer tests |
| tests/assert_type/routers.py | Added converted router tests |
| tests/assert_type/request.py | Added converted request tests |
| tests/assert_type/pagination.py | Added converted pagination tests |
| tests/assert_type/mixins.py | Added converted mixin tests |
| tests/assert_type/filters.py | Added converted filter tests |
| tests/assert_type/fields.py | Added converted field tests |
| tests/assert_type/exceptons.py | Added converted exception tests (note: filename typo) |
| tests/assert_type/decorators.py | Added converted decorator tests |
| tests/assert_type/compat.py | Added converted compatibility tests |
| pyproject.toml | Added linter exceptions and banned API for assert_type tests |
| .github/workflows/test.yml | Added mypy validation step for test files |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
5db5e09 to
35b5792
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am ok with this, but I didn't review all the test changes, I hope that they are the same :)
I tried to convert existing tests with minimal changes -- such that in many cases "git blame" can still find the commit where the original
.ymltests were added.Tests written in regular
.pyfiles usingassert_type()have lots of advantages compared topytest-mypy-plugins.yml-format tests:However, not all tests can be converted --
pytest-mypy-pluginstests are still useful for more complex cases:models.py)