Support for interleaved errors
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
Research direction
Start by reviewing the linked implementation in tests/mypy_helpers.py and its usage in tests/test_plugin.py, then inspect assertion rewriting in tests/init.py. Compare the proposed interleaved-error format with the current test expectations and determine the required plugin behavior and test coverage before deciding whether the approach can be supported.
Written by the indexing model from the issue text.
Description
Here's what I came up with while trying to replicate mypy's own testcases, which interleave the expected errors in the source code like so:
https://github.com/ikonst/pynamodb-mypy/blob/9453404f576c4ead04749d61eb041e10bec13229/tests/test_plugin.py
The implementation is here:
https://github.com/ikonst/pynamodb-mypy/blob/9453404f576c4ead04749d61eb041e10bec13229/tests/mypy_helpers.py
In a failure case, the failed assertion output will look like:
> assert actual == expected
E assert 'from pynamod...ibute "lower"' == 'from pynamodb..._attr.lower()'
E from pynamodb.attributes import UnicodeAttribute
E from pynamodb.models import Model
E
E class MyModel(Model):
E my_attr = UnicodeAttribute(null=True)
E
E reveal_type(MyModel.my_attr) # E: Revealed type is 'pynamodb.attributes._NullableAttribute[pynamodb.attributes.UnicodeAttribute, builtins.str]'
E reveal_type(MyModel().my_attr) # E: Revealed type is 'Union[builtins.str*, None]'
E - MyModel().my_attr.lower() # E: Item "None" of "Optional[str]" has no attribute "lower"
E + MyModel().my_attr.lower()
Of course, this requires assertion rewriting, which would've been done in the pytest plugin normally:
https://github.com/ikonst/pynamodb-mypy/blob/9453404f576c4ead04749d61eb041e10bec13229/tests/__init__.py#L3
There are two advantages of interleaving the errors in the test code:
- changing the test code does not necessitate updating of line numbers
- updating the test code is easier (by diffing the program against the "expected program", i.e. data-driven testing)
Have you considered allowing a similar approach?
- Dominant language
- Python
- Stars
- 257
- Forks
- 33
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from realpython/pytest-mypy
-
integration
Difficulty 3/5 1-2 days Newbie friendliness 38/100
realpython/pytest-mypy#196 · 2 comments ·
-
realpython/pytest-mypy#190 · 1 comment · 1 assignee ·
-
integration
Difficulty 3/5 1-2 days Newbie friendliness 38/100
realpython/pytest-mypy#160 · 4 comments ·
-
integration
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
realpython/pytest-mypy#138 · 2 comments · 2 reactions ·
-
Expected mypy errors Open
realpython/pytest-mypy#105 · 4 comments · 1 assignee ·
All issues in realpython/pytest-mypy
Similar issues
-
essnmx good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
[Feature] 奇物选择添加优先级 Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
syfoud/Simulated_Scepter#174 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Giskard-AI/giskard-oss#2840 · 1 comment ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Openarea: repo bug perceived difficulty: 2
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
yeti-platform/yeti#1380 ·