-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Rewrite .test as .py #15326
Comments
Syntax highlighting seems useful! I think the proposed syntax is a little magical; I wouldn't want to overload decorators like this. Maybe just comments to mark test case dividers would work well... We already do that for flags. Also see mypyc/mypyc#959 where dosisod wrote some syntax highlighting for mypyc test cases |
For what it's worth, in pyanalyze (https://github.com/quora/pyanalyze/blob/8d0e9d4fcfa0c5875dd5ff93c6ec1ae188bf9738/pyanalyze/test_name_check_visitor.py#L174) I use a system similar to what you propose, where a decorator marks test cases written in nested functions. The framework then uses Mypy could use this kind of system too. It sometimes doesn't work in cases where the code cannot be placed within a function (e.g., |
Whichever mechanism we choose, I'd like it to be more ... structured? i.e. that annotations/options/modifiers would be defined in some place (call it a "schema") rather than have a loose set of conventions (like Then one can map (especially naively by using a "go to definition" in their editor) from an option to whatever it does, and discover what other options exist. Screen.Recording.2023-05-31.at.11.00.31.AM.mov
The intention is not to let pytest naively load the module and collect functions that begin with "test_". As I said, not CPython nor Mypy would be fed the module as is. Instead, we would still implement a custom pytest collector, which might leverage AST for parsing if that works out. The Pythonic syntax will only be used as a form of data-serialization language that gets favorable IDE treatment and familiar to Mypy contributors.
See my proposal for a syntax above ("[file a.py] would become: ..."). |
@ikonst in PyCharm/Idea you can associate the Of course, this isn't a solution, but it's better than nothing. |
Many of us are using editors that handle Python code (syntax highlighting, symbol browsing). Would it be a good idea to restructure the .test data-files as Python files?
I've been musing about it for a while, so hear me out, then let me know if it's a stupid idea :)
Example:
To clarify, this wouldn't be true Python code, i.e. it won't be fed directly to CPython or Mypy; rather, it'll be a Python-flavored data file — perhaps parsed by AST (if feasible and performant), but where the function bodies are passed to the current machinery as text.
Extra qualifies like
# flags: --strict-optional
could be represented as decorators, e.g.[case testFoo-xfail]
would become:[out]
would become:[file a.py]
would become:Benefits:
from mypy.testcase import expected_output
and thenCons:
The text was updated successfully, but these errors were encountered: