Fix TestTypeHints.test_doc_examples#56388
Fix TestTypeHints.test_doc_examples#56388samestep wants to merge 4 commits intopytorch:masterfrom samestep:test-type-hints-cwd-test
Conversation
💊 CI failures summary and remediationsAs of commit 3031505 (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions to the (internal) Dr. CI Users group. |
TestTypeHints.test_doc_examples
TestTypeHints.test_doc_examples|
@samestep has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
| # entire process! | ||
| with set_cwd(str(repo_rootdir)): | ||
| (stdout, stderr, result) = mypy.api.run([ | ||
| '--cache-dir=.mypy_cache/doc', |
There was a problem hiding this comment.
It seems like it'd be cleaner to use the --config-file option and pass it an absolute path to the mypy.ini rather than changing the cwd, would that still work?
There was a problem hiding this comment.
that doesn't immediately work (it requires modifications to mypy_plugins/check_mypy_version.py), and I also simply prefer this because it matches up with the way we otherwise use mypy in CI (from the repo root)
Co-authored-by: Rong Rong <walterddr.walterddr@gmail.com>
|
@samestep has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
| repo_rootdir = Path(__file__).resolve().parent.parent | ||
| # TODO: Would be better not to chdir here, this affects the | ||
| # entire process! |
There was a problem hiding this comment.
could you please also include the github URL for the issue you created to discuss this?
There was a problem hiding this comment.
I didn't write this comment; it's from here: 8cd4dac#diff-a0c9bbf5bd1854c65f36d0a26a1a74c1bb0e0d0fa8c77d6573e9531bd310721eL166-L167
Codecov Report
@@ Coverage Diff @@
## master #56388 +/- ##
==========================================
- Coverage 77.03% 77.03% -0.01%
==========================================
Files 1924 1924
Lines 190583 190583
==========================================
- Hits 146819 146814 -5
- Misses 43764 43769 +5 |
Summary: pytorch#54268 removed `test_run_mypy` since now we're running `mypy` as its own job in GitHub Actions, but previously we used this `set_cwd` context manager in that test to ensure that we picked up the `mypy` config correctly. However, for some reason, we have not been doing that in `test_doc_examples`, which has been succeeding in CI for a while despite being broken. Specifically, [`run_test.py` changes the working directory to `test/` before running test files](https://github.com/pytorch/pytorch/blob/48aaea3359cffe7982ce24b8742c7a1f4b456a92/test/run_test.py#L534-L535), which is contrary to [what `CONTRIBUTING.md` instructs developers to do](https://github.com/pytorch/pytorch/blob/48aaea3359cffe7982ce24b8742c7a1f4b456a92/CONTRIBUTING.md#python-unit-testing). As a result, in CI, `test/test_type_hints.py` has been passing in CI, but if you run it locally from the root of the repo, this you get this error: ``` F ====================================================================== FAIL: test_doc_examples (__main__.TestTypeHints) Run documentation examples through mypy. ---------------------------------------------------------------------- Traceback (most recent call last): File "test/test_type_hints.py", line 127, in test_doc_examples self.fail(f"mypy failed:\n{stdout}") AssertionError: mypy failed: test/generated_type_hints_smoketest.py:851: error: Name 'tensor' is not defined [name-defined] test/generated_type_hints_smoketest.py:853: error: Name 'tensor' is not defined [name-defined] Found 2 errors in 1 file (checked 1 source file) ---------------------------------------------------------------------- Ran 1 test in 1.416s FAILED (failures=1) ``` Pull Request resolved: pytorch#56388 Test Plan: Before this PR, the first of the following two commands should fail (since that is essentially what is run in CI), but the second should fail: ``` python test/run_test.py -i test_type_hints python test/test_type_hints.py ``` After this PR, both commands should succeed. Reviewed By: driazati Differential Revision: D27860173 Pulled By: samestep fbshipit-source-id: efb82fffd7ccb04d0331824b40bdef7bbc319c98
#54268 removed
test_run_mypysince now we're runningmypyas its own job in GitHub Actions, but previously we used thisset_cwdcontext manager in that test to ensure that we picked up themypyconfig correctly. However, for some reason, we have not been doing that intest_doc_examples, which has been succeeding in CI for a while despite being broken.Specifically,
run_test.pychanges the working directory totest/before running test files, which is contrary to whatCONTRIBUTING.mdinstructs developers to do. As a result, in CI,test/test_type_hints.pyhas been passing in CI, but if you run it locally from the root of the repo, this you get this error:Test plan:
Before this PR, the first of the following two commands should fail (since that is essentially what is run in CI), but the second should fail:
After this PR, both commands should succeed.