Repository navigation
Add skip for tests using libtorchbind_test when library is not found - #193122
dominikjastrzebskix wants to merge 3 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/193122
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit aa005f0 with merge base e268912 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
@pytorchbot merge |
Merge failedReason: This PR needs a If not, please add the To add a label, you can comment to pytorchbot, for example For more information, see Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Fixes issue found: #4105 Do not merge before: pytorch/pytorch#193122 Upstream change now tries to load the library and only if it fails skips the test. There is no longer need to have the skip hard-coded for windows.
Fixes issue found: #4105 Do not merge before: pytorch/pytorch#193122 Upstream change now tries to load the library and only if it fails skips the test. There is no longer need to have the skip hard-coded for windows.
…ytorch#193122) Fixes issues found here: intel/torch-xpu-ops#4105 Pull Request resolved: pytorch#193122 Approved by: https://github.com/pbielak, https://github.com/zou3519, https://github.com/guangyey
pytorch#193122 made `load_torchbind_test_lib()` raise `unittest.SkipTest` instead of `OSError` when `libtorchbind_test.so` is not present, which is the case on any wheel install since 2.13 stopped shipping the test-only libraries. `WeakKeyDictionaryScriptObjectTestCase` only calls it from `__init__` under `except unittest.SkipTest: return`. unittest does not honour `SkipTest` raised from `__init__`, so the class is never skipped; the early return just leaves the instance without `reference`, `other` and `inmapping`, and the 8 tests that use them fail with `AttributeError` while the other 6 pass. Call it from `setUp` as well, which is where unittest can act on the `SkipTest`. The `__init__` copy stays: it is what decides whether the attributes can be built at all, and its `except SkipTest: return` is now harmless because `setUp` raises the same exception where it counts. The attribute setup deliberately stays in `__init__` too. Moving it into `setUp` also works under plain pytest, but `PYTORCH_TEST_WITH_DYNAMO=1` compiles `setUp`, and tracing the `_TorchScriptTesting._Foo` constructions in `_reference()` fails with "haven't registered a fake class". Keeping them out of `setUp` keeps the dynamo_wrapped shard green. Test Plan: `2.15.0.dev20260909+xpu`, which contains pytorch#193122 and does not ship the library. The "library present" rows copy a `libtorchbind_test.so` from a `BUILD_TEST=1` source build into `torch/lib`, to confirm coverage is not silently dropped when the library is available. ``` python -m pytest -q test/test_weak.py::WeakKeyDictionaryScriptObjectTestCase PYTORCH_TEST_WITH_DYNAMO=1 python -m pytest -q test/test_weak.py::WeakKeyDictionaryScriptObjectTestCase ``` | | before | after | |---|---|---| | library absent, eager | 8 failed, 6 passed | 14 skipped | | library absent, dynamo | 8 failed, 6 passed | 14 skipped | | library present, eager | 14 passed | 14 passed | | library present, dynamo | 14 passed | 14 passed | ``` lintrunner --skip CLANGTIDY,CLANGFORMAT test/test_weak.py ``` Related: intel/torch-xpu-ops#5127 Authored with an AI assistant.
pytorch#193122 made `load_torchbind_test_lib()` raise `unittest.SkipTest` instead of `OSError` when `libtorchbind_test.so` is not present, which is the case on any wheel install since 2.13 stopped shipping the test-only libraries. `WeakKeyDictionaryScriptObjectTestCase` calls it from `__init__` under `except unittest.SkipTest: return`. unittest only honours `SkipTest` from `setUp` or the test method, so the class is never skipped; the early return just leaves the instance without `reference`, `other` and `inmapping`, and the 8 tests that use them fail with `AttributeError` while the other 6 pass. Moving the load and the attribute setup into `setUp` lets unittest see the `SkipTest`. Removing the `__init__` override also stops bypassing `TestCase.__init__`, which the old code skipped by calling `unittest.TestCase.__init__` directly. The alternative was to catch `OSError`/`SkipTest` in `__init__` and mark the class skipped some other way, but `setUp` is where the other four callers of `load_torchbind_test_lib()` already do this, so this keeps them uniform. Test Plan: Against a nightly wheel that contains pytorch#193122 and does not ship `libtorchbind_test.so`: ``` pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/xpu python -m pytest -q test/test_weak.py::WeakKeyDictionaryScriptObjectTestCase ``` before: `8 failed, 6 passed` after: `14 skipped` Repeating both runs with `libtorchbind_test.so` copied into `torch/lib` to confirm coverage is not silently dropped when the library is available: ``` cp libtorchbind_test.so "$(python -c 'import torch,os;print(os.path.dirname(torch.__file__))')/lib/" python -m pytest -q test/test_weak.py::WeakKeyDictionaryScriptObjectTestCase ``` before: `14 passed` after: `14 passed` ``` lintrunner --skip CLANGTIDY,CLANGFORMAT test/test_weak.py ``` Authored with an AI assistant.
Fixes issue found: #4105 Do not merge before: pytorch/pytorch#193122 Upstream change now tries to load the library and only if it fails skips the test. There is no longer need to have the skip hard-coded for windows.
On a wheel install `libtorchbind_test.so` is absent, and `WeakKeyDictionaryScriptObjectTestCase` errors instead of skipping. Two causes: 1. `load_torchbind_test_lib()` never raises `SkipTest` anymore. pytorch#193122 added an `.exists()` check for that, but pytorch#194884 later made `find_library_location` raise `FileNotFoundError` when the library is missing, so the check became unreachable. Fix: convert the `FileNotFoundError` to `SkipTest` in the loader. This also fixes the other callers of the loader. 2. The test class called the loader from `__init__`, and unittest ignores `SkipTest` raised there. Fix: load in `setUp`. Under `PYTORCH_TEST_WITH_DYNAMO`, `setUp` is compiled and tracing the `_TorchScriptTesting._Foo` construction fails on the unregistered fake class, so the fixtures are built in a `torch._dynamo.disable`'d helper. Test Plan: On `2.15.0.dev20260915+xpu` (no torchbind library), with main's `find_library_location` injected and this PR's `torchbind_impls.py` and `test_weak.py`: ``` python test/test_weak.py -k ScriptObject # OK (skipped=14) PYTORCH_TEST_WITH_DYNAMO=1 python test/test_weak.py -k ScriptObject # OK (skipped=14) ``` Without the fix: 14 errors (`FileNotFoundError`). The library-present path is covered by CI. Fixes intel/torch-xpu-ops#5127 Authored with an AI assistant.
On a wheel install `libtorchbind_test.so` is absent, and `WeakKeyDictionaryScriptObjectTestCase` errors instead of skipping. Two causes: 1. `load_torchbind_test_lib()` never raises `SkipTest` anymore. pytorch#193122 added an `.exists()` check for that, but pytorch#194884 later made `find_library_location` raise `FileNotFoundError` when the library is missing, so the check became unreachable. Fix: convert the `FileNotFoundError` to `SkipTest` in the loader. This also fixes the other callers of the loader. 2. The test class called the loader from `__init__`, and unittest ignores `SkipTest` raised there. Fix: load in `setUp`. Under `PYTORCH_TEST_WITH_DYNAMO`, `setUp` is compiled and tracing the `_TorchScriptTesting._Foo` construction fails on the unregistered fake class, so the fixtures are built in a `torch._dynamo.disable`'d helper. Test Plan: On `2.15.0.dev20260915+xpu` (no torchbind library), with main's `find_library_location` injected and this PR's `torchbind_impls.py` and `test_weak.py`: ``` python test/test_weak.py -k ScriptObject # OK (skipped=14) PYTORCH_TEST_WITH_DYNAMO=1 python test/test_weak.py -k ScriptObject # OK (skipped=14) ``` Without the fix: 14 errors (`FileNotFoundError`). The library-present path is covered by CI. Fixes intel/torch-xpu-ops#5127 Authored with an AI assistant.
On a wheel install `libtorchbind_test.so` is absent, and `WeakKeyDictionaryScriptObjectTestCase` errors instead of skipping. Two causes: 1. `load_torchbind_test_lib()` never raises `SkipTest` anymore. pytorch#193122 added an `.exists()` check for that, but pytorch#194884 later made `find_library_location` raise `FileNotFoundError` when the library is missing, so the check became unreachable. Fix: convert the `FileNotFoundError` to `SkipTest` in the loader. This also fixes the other callers of the loader. 2. The test class called the loader from `__init__`, and unittest ignores `SkipTest` raised there. Fix: load in `setUp`. Under `PYTORCH_TEST_WITH_DYNAMO`, `setUp` is compiled and tracing the `_TorchScriptTesting._Foo` construction fails on the unregistered fake class, so the fixtures are built in a `torch._dynamo.disable`'d helper. Test Plan: On `2.15.0.dev20260915+xpu` (no torchbind library), with main's `find_library_location` injected and this PR's `torchbind_impls.py` and `test_weak.py`: ``` python test/test_weak.py -k ScriptObject # OK (skipped=14) PYTORCH_TEST_WITH_DYNAMO=1 python test/test_weak.py -k ScriptObject # OK (skipped=14) ``` Without the fix: 14 errors (`FileNotFoundError`). The library-present path is covered by CI. Fixes intel/torch-xpu-ops#5127 Authored with an AI assistant.
On a wheel install `libtorchbind_test.so` is absent, and `WeakKeyDictionaryScriptObjectTestCase` errors instead of skipping. Two causes: 1. `load_torchbind_test_lib()` never raises `SkipTest` anymore. pytorch#193122 added an `.exists()` check for that, but pytorch#194884 later made `find_library_location` raise `FileNotFoundError` when the library is missing, so the check became unreachable. Fix: convert the `FileNotFoundError` to `SkipTest` in the loader. This also fixes the other callers of the loader. 2. The test class called the loader from `__init__`, and unittest ignores `SkipTest` raised there. Fix: load in `setUpClass`, which skips the whole class and loads the library once. Under `PYTORCH_TEST_WITH_DYNAMO`, `setUp` is compiled and tracing the `_TorchScriptTesting._Foo` construction fails on the unregistered fake class, so the fixtures are built in a `torch._dynamo.disable`'d helper. Test Plan: On `2.15.0.dev20260915+xpu` (no torchbind library), with main's `find_library_location` injected and this PR's `torchbind_impls.py` and `test_weak.py`: ``` python test/test_weak.py -k ScriptObject # OK (skipped=1) PYTORCH_TEST_WITH_DYNAMO=1 python test/test_weak.py -k ScriptObject # OK (skipped=1) ``` Without the fix: 14 errors (`FileNotFoundError`). The library-present path is covered by CI. Fixes intel/torch-xpu-ops#5127 Authored with an AI assistant.
On a wheel install `libtorchbind_test.so` is absent, and `WeakKeyDictionaryScriptObjectTestCase` errors instead of skipping. Two causes: 1. `load_torchbind_test_lib()` never raises `SkipTest` anymore. pytorch#193122 added an `.exists()` check for that, but pytorch#194884 later made `find_library_location` raise `FileNotFoundError` when the library is missing, so the check became unreachable. Fix: convert the `FileNotFoundError` to `SkipTest` in the loader. This also fixes the other callers of the loader. 2. The test class called the loader from `__init__`, and unittest ignores `SkipTest` raised there. Fix: load in `setUpClass`, which skips the whole class and loads the library once. Under `PYTORCH_TEST_WITH_DYNAMO`, `setUp` is compiled and tracing the `_TorchScriptTesting._Foo` construction fails on the unregistered fake class, so the fixtures are built in a `torch._dynamo.disable`'d helper. Test Plan: On `2.15.0.dev20260915+xpu` (no torchbind library), with main's `find_library_location` injected and this PR's `torchbind_impls.py` and `test_weak.py`: ``` python test/test_weak.py -k ScriptObject # OK (skipped=1) PYTORCH_TEST_WITH_DYNAMO=1 python test/test_weak.py -k ScriptObject # OK (skipped=1) ``` Without the fix: 14 errors (`FileNotFoundError`). The library-present path is covered by CI. Fixes intel/torch-xpu-ops#5127 Authored with an AI assistant.
On a wheel install `libtorchbind_test.so` is absent, and `WeakKeyDictionaryScriptObjectTestCase` errors instead of skipping. Two causes: 1. `load_torchbind_test_lib()` never raises `SkipTest` anymore. pytorch#193122 added an `.exists()` check for that, but pytorch#194884 later made `find_library_location` raise `FileNotFoundError` when the library is missing, so the check became unreachable. Fix: convert the `FileNotFoundError` to `SkipTest` in the loader. This also fixes the other callers of the loader. 2. The test class called the loader from `__init__`, and unittest ignores `SkipTest` raised there. Fix: load in `setUpClass`, which skips the whole class and loads the library once. Under `PYTORCH_TEST_WITH_DYNAMO`, `setUp` is compiled and tracing the `_TorchScriptTesting._Foo` construction fails on the unregistered fake class, so the fixtures are built in a `torch._dynamo.disable`'d helper. Test Plan: On `2.15.0.dev20260915+xpu` (no torchbind library), with main's `find_library_location` injected and this PR's `torchbind_impls.py` and `test_weak.py`: ``` python test/test_weak.py -k ScriptObject # OK (skipped=1) PYTORCH_TEST_WITH_DYNAMO=1 python test/test_weak.py -k ScriptObject # OK (skipped=1) ``` Without the fix: 14 errors (`FileNotFoundError`). The library-present path is covered by CI. Fixes intel/torch-xpu-ops#5127 Authored with an AI assistant.
On a wheel install `libtorchbind_test.so` is absent, and `WeakKeyDictionaryScriptObjectTestCase` errors instead of skipping. Two causes: 1. `load_torchbind_test_lib()` never raises `SkipTest` anymore. pytorch#193122 added an `.exists()` check for that, but pytorch#194884 later made `find_library_location` raise `FileNotFoundError` when the library is missing, so the check became unreachable. Fix: convert the `FileNotFoundError` to `SkipTest` in the loader. This also fixes the other callers of the loader. 2. The test class called the loader from `__init__`, and unittest ignores `SkipTest` raised there. Fix: load in `setUpClass`, which skips the whole class and loads the library once. Under `PYTORCH_TEST_WITH_DYNAMO`, `setUp` is compiled and tracing the `_TorchScriptTesting._Foo` construction fails on the unregistered fake class, so the fixtures are built in a `torch._dynamo.disable`'d helper. Test Plan: On `2.15.0.dev20260915+xpu` (no torchbind library), with main's `find_library_location` injected and this PR's `torchbind_impls.py` and `test_weak.py`: ``` python test/test_weak.py -k ScriptObject # OK (skipped=1) PYTORCH_TEST_WITH_DYNAMO=1 python test/test_weak.py -k ScriptObject # OK (skipped=1) ``` Without the fix: 14 errors (`FileNotFoundError`). The library-present path is covered by CI. Fixes intel/torch-xpu-ops#5127 Authored with an AI assistant.
On a wheel install `libtorchbind_test.so` is absent, and `WeakKeyDictionaryScriptObjectTestCase` errors instead of skipping. Two causes: 1. `load_torchbind_test_lib()` never raises `SkipTest` anymore. pytorch#193122 added an `.exists()` check for that, but pytorch#194884 later made `find_library_location` raise `FileNotFoundError` when the library is missing, so the check became unreachable. Fix: convert the `FileNotFoundError` to `SkipTest` in the loader. This also fixes the other callers of the loader. 2. The test class called the loader from `__init__`, and unittest ignores `SkipTest` raised there. Fix: load in `setUpClass`, which skips the whole class and loads the library once. Under `PYTORCH_TEST_WITH_DYNAMO`, `setUp` is compiled and tracing the `_TorchScriptTesting._Foo` construction fails on the unregistered fake class, so the fixtures are built in a `torch._dynamo.disable`'d helper. Test Plan: On `2.15.0.dev20260915+xpu` (no torchbind library), with main's `find_library_location` injected and this PR's `torchbind_impls.py` and `test_weak.py`: ``` python test/test_weak.py -k ScriptObject # OK (skipped=1) PYTORCH_TEST_WITH_DYNAMO=1 python test/test_weak.py -k ScriptObject # OK (skipped=1) ``` Without the fix: 14 errors (`FileNotFoundError`). The library-present path is covered by CI. Fixes intel/torch-xpu-ops#5127 Authored with an AI assistant.
Fixes issues found here: intel/torch-xpu-ops#4105