Port NumPy typing testing style to PyTorch#52408
Port NumPy typing testing style to PyTorch#52408guilhermeleobas wants to merge 11 commits intopytorch:masterfrom guilhermeleobas:mypy_tests
Conversation
💊 CI failures summary and remediationsAs of commit 6b42dfa (more details on the Dr. CI page):
🕵️ 1 new failure recognized by patternsThe following CI failures do not appear to be due to upstream breakages:
|
rgommers
left a comment
There was a problem hiding this comment.
Thanks @guilhermeleobas, looks great from a first look. I will do a more detailed review later.
Would it make sense to also add a pass/ and a fail/ directory (like NumPy has too) with a couple of tests in each? Or do you prefer to leave that for later.
|
Cc @malfet and @walterddr for visibility. This PR introduces a new, more compact and extensive, test style for type annotation tests. As suggested in #16574 (comment). The machinery is largely taken from NumPy, this approach is working well there. |
|
@guilhermeleobas can you please rebase your change against https://github.com/pytorch/pytorch/tree/viable/strict ? (to see clean picture on the PR) |
@rgommers, I can add both in a later PR.
@malfet, done! |
Codecov Report
@@ Coverage Diff @@
## master #52408 +/- ##
==========================================
- Coverage 80.76% 80.42% -0.34%
==========================================
Files 1975 1975
Lines 216841 216841
==========================================
- Hits 175134 174404 -730
- Misses 41707 42437 +730 |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@malfet has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
walterddr
left a comment
There was a problem hiding this comment.
looks good. do we want to add the test into test/run_test.py list and run it on CI?
Yes, I think so.
Sounds good. Another thing that would be good as a follow-up is to get rid of everything in |
|
Can you please add this new .py file to |
|
Done @malfet |
| import shutil | ||
| from typing import IO, Dict, List | ||
|
|
||
| import pytest |
There was a problem hiding this comment.
Please remove pytest dependency (as I've mentioned in my previous comment, pytorch test infra is not compatible with it yet)
There was a problem hiding this comment.
Oops, my bad. Do you know if pytest support is landing in a near future?
There was a problem hiding this comment.
as far as i know there's no plan. see: https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md#unit-testing
There was a problem hiding this comment.
Please remove
pytestdependency (as I've mentioned in my previous comment, pytorch test infra is not compatible with it yet)
After looking into it, this isn't quite right - there are unconditional import pytest statements in the codebase (see
#11578 (comment)). There's no point spending significant effort rewriting this bit of by now well-tested code. I think the correct solution is to keep this file as is, and:
- add the file name to
USE_PYTEST_LISTintest/run_test.py - make the test runnable standalone by, at the end of the file, adding:
if __name__ == '__main__':
pytest.main([__file__])
There was a problem hiding this comment.
Thanks for the suggestion Ralf. I've put the file on USE_PYTEST_LIST
| if os.path.isdir(CACHE_DIR): | ||
| shutil.rmtree(CACHE_DIR) |
There was a problem hiding this comment.
Can you add a comment why cache needs to be invalidated before running the tests?
MyPy should be capable of updating the cache if files have changed between the runs, shouldn't it?
There was a problem hiding this comment.
This was also inherited from NumPy source code. But from my personal experience, 99% of the time mypy is capable of invalidating the cache. Only in a few specific scenarios this wasn't true.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@malfet has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
#53167) Summary: This is a follow-up PR of #52408 and move/convert all files under `test/type_hint_tests/*.py` to use the new test style. Pull Request resolved: #53167 Reviewed By: ejguan Differential Revision: D27081041 Pulled By: walterddr fbshipit-source-id: 56508083800a5e12a7af88d095ca26229f0df358
Summary: ref: pytorch#16574 Pull Request resolved: pytorch#52408 Reviewed By: anjali411 Differential Revision: D26654687 Pulled By: malfet fbshipit-source-id: 6feb603d8fb03c2ba2a01468bfde1a9901e889fd
Summary: This is a follow-up PR of pytorch#52408 and includes the `pass/` and `fail/` directories. Pull Request resolved: pytorch#54234 Reviewed By: walterddr Differential Revision: D27681410 Pulled By: malfet fbshipit-source-id: e6817df77c758f4c1295ea62613106c71cfd3fc3
Summary: ref: pytorch#16574 Pull Request resolved: pytorch#52408 Reviewed By: anjali411 Differential Revision: D26654687 Pulled By: malfet fbshipit-source-id: 6feb603d8fb03c2ba2a01468bfde1a9901e889fd
pytorch#53167) Summary: This is a follow-up PR of pytorch#52408 and move/convert all files under `test/type_hint_tests/*.py` to use the new test style. Pull Request resolved: pytorch#53167 Reviewed By: ejguan Differential Revision: D27081041 Pulled By: walterddr fbshipit-source-id: 56508083800a5e12a7af88d095ca26229f0df358
Summary: This is a follow-up PR of pytorch#52408 and includes the `pass/` and `fail/` directories. Pull Request resolved: pytorch#54234 Reviewed By: walterddr Differential Revision: D27681410 Pulled By: malfet fbshipit-source-id: e6817df77c758f4c1295ea62613106c71cfd3fc3
ref: #16574