pytorch
34d0bd5b - Fix TestTypeHints.test_doc_examples (#56388)

Commit
3 years ago
Fix TestTypeHints.test_doc_examples (#56388) Summary: https://github.com/pytorch/pytorch/issues/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: https://github.com/pytorch/pytorch/pull/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
Author
Parents
Loading