-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
provide tools for testing projects that use mypy (e.g. mypy.tests.data pytest plugin) #4366
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
Comments
There are plans to do some not insignificant refactoring to move |
I have to repeat what I've said before -- the mypy package is *not* a
public API and we don't make any attempts at preserving compatibility
across releases. Please don't build applications or libraries depending on
mypy internals. And that includes the mypy.test subpackage. Please.
|
I get that. This is a feature request to make a pytest plugin that is public. I think that making it easy to test statically type-checked projects is essential to fostering the mypy community. |
Updated the title to clarify the request |
I'm not sure I understand what you want to do with that plugin.
mypy.test.data is mostly a parser for the kind of test files that are used
in mypy's unit tests. How exactly do you think other statically
type-checked benefit from this? More in particular, how does *your* project
benefit from this? Are you writing such test files? You're welcome to copy
the code and release it as a separate package, and maybe mypy can depend on
your version if you maintain it well.
|
Yes. All the problems that you faced when designing a way to test mypy, other developers will soon face when testing their stubs. I saw no reason to reinvent the wheel.
Once #1673 is completed, I may take you up on that, though I'll admit I'm surprised that you don't think it would be easier to maintain within mypy. |
It still seems to me that testing mypy is very different from testing
stubs, but I'm happy to agree to disagree.
…On Dec 14, 2017 13:09, "Chad Dombrova" ***@***.***> wrote:
mypy.test.data is mostly a parser for the kind of test files that are used
in mypy's unit tests. How exactly do you think other statically
type-checked benefit from this? More in particular, how does *your*
project
benefit from this? Are you writing such test files?
Yes. All the problems that you faced when designing a way to test mypy,
other developers will soon face when testing their stubs. I saw no reason
to reinvent the wheel.
You're welcome to copy
the code and release it as a separate package, and maybe mypy can depend on
your version if you maintain it well.
Once #1673 <#1673> is completed, I
may take you up on that, though I'll admit I'm surprised that you don't
think it would be easier to maintain within mypy.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4366 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACwrMtBZKjSxA09Bqy3CmW-l6l-lvfEQks5tAY6cgaJpZM4RCj-r>
.
|
Not to belabor the point, but that's why mypy has several testing systems covering different strategies (e.g. some testing the code itself, and some testing the cli). |
Just added #4369 which removes myunit, but will not be the last PR in the migration. @chadrik I'm not sure I understand - do you want to assert something about mypy's error output? Because the I don't think the error messages themselves are (or should be) part of mypy's public API. Or maybe you are talking about something as abstract as Note that your test code is already broken (take a look at the current PythonEvaluationSuite) and I believe it is likely to break again often in the near future. |
Yes. Here's our test suite: https://github.com/chadrik/attrs/blob/pyi_stubs/tests/test_stubs.test Our goal is not to statically type check our library; the library itself contains no type comments. If that were the case we would simply assert that mypy returns 0. Our goal is to test that the stubs, which we now consider part of our public API, behave as expected. Like any unit test, that means setting up specific scenarios and asserting that the the results are as expected. e.g.
Most of the "errors" we care about are generated by [case test_validators]
# cmd: mypy a.py
[file a.py]
import attr
from attr.validators import in_, and_, instance_of
a = attr.ib(type=int, validator=in_([1, 2, 3]))
b = attr.ib(type=int, validator=[in_([1, 2, 3]), instance_of(int)])
c = attr.ib(type=int, validator=(in_([1, 2, 3]), instance_of(int)))
d = attr.ib(type=int, validator=and_(in_([1, 2, 3]), instance_of(int)))
e = attr.ib(type=int, validator=1) # error
[out]
a.py:8: error: Argument 2 has incompatible type "int"; expected "Union[Callable[[Any, Attribute[Any], int], Any], List[Callable[[Any, Attribute[Any], int], Any]], Tuple[Callable[[Any, Attribute[Any], int], Any], ...]]" Another feature that I would love is the ability to statically type-check doc snippets, like doctests for mypy. I whipped up a sphinx extension to do this, but it would also rely on string matching error output.
This is a good point, and it's an annoyance that I was willing accept given the dearth of options (and my desire to focus on writing tests instead of writing a test runner). This problem could be mitigated (though not entirely avoided) by improving the mypy pytest plugin to support glob or regex matching. Maybe a better solution to this problem is this other issue that I opened to support type checking Using
|
I think I agree with Guido that it doesn't make sense to have a public API. Some common test framework for stubs will have to evolve elsewhere. |
I was very glad to see that
mypy.tests
was added into the mypy package a few releases back, because that opened up the possibility of usingmypy.tests.data
as apytest
plugin for testing other projects. I used it in the static typing tests for attrs: https://github.com/chadrik/attrs/blob/pyi_stubs/tests/test_stubs.pyUnfortunately commit
e03780623
added an import ofmypy.test.config
which causes an error because the module expect to find atest-data/unit
directory at the same level as the root mypy directory:I'm pip installing mypy, so naturally it's not there.
I recognize that I've gone a bit out on a limb using
mypy.tests.data
since it's not a public API, but it's really really useful. I'd like to request that this become a public plugin, and I think a good first step towards this is to make the constants stored inmypy.tests.config
configurable via pytest. If you like the idea, I'm glad to submit a PR.The text was updated successfully, but these errors were encountered: