Skip to content

Add skip for tests using libtorchbind_test when library is not found - #193122

Closed
dominikjastrzebskix wants to merge 3 commits into
pytorch:mainfrom
dominikjastrzebskix:djastrzx-libtorchbind_test
Closed

dominikjastrzebskix wants to merge 3 commits into
pytorch:mainfrom
dominikjastrzebskix:djastrzx-libtorchbind_test

Conversation

@dominikjastrzebskix

Copy link
Copy Markdown
Contributor

Fixes issues found here: intel/torch-xpu-ops#4105

@pytorch-bot

pytorch-bot Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

🔗 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 Failures

As of commit aa005f0 with merge base e268912 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@dominikjastrzebskix
dominikjastrzebskix marked this pull request as ready for review August 13, 2026 15:43
@albanD
albanD requested a review from zou3519 August 15, 2026 22:22
@albanD albanD added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Aug 15, 2026
@pbielak pbielak added the ciflow/trunk Trigger trunk jobs on your pull request label Aug 26, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@pbielak
pbielak requested a review from guangyey August 26, 2026 13:16

@guangyey guangyey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@guangyey

guangyey commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Details for Dev Infra team Raised by workflow job

@guangyey guangyey added the topic: not user facing topic category label Sep 2, 2026
@guangyey

guangyey commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

torchxpubot pushed a commit to intel/torch-xpu-ops that referenced this pull request Sep 3, 2026
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.
zxd1997066 pushed a commit to intel/torch-xpu-ops that referenced this pull request Sep 5, 2026
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.
ZhaoqiongZ added a commit to ZhaoqiongZ/pytorch that referenced this pull request Sep 10, 2026
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.
ZhaoqiongZ added a commit to ZhaoqiongZ/pytorch that referenced this pull request Sep 10, 2026
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.
@dominikjastrzebskix
dominikjastrzebskix deleted the djastrzx-libtorchbind_test branch September 15, 2026 13:30
orrangetabby17 pushed a commit to intel/torch-xpu-ops that referenced this pull request Oct 8, 2026
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.
ZhaoqiongZ added a commit to ZhaoqiongZ/pytorch that referenced this pull request Nov 12, 2026
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.
pytorchmergebot pushed a commit to ZhaoqiongZ/pytorch that referenced this pull request Nov 24, 2026
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.
pytorchmergebot pushed a commit to ZhaoqiongZ/pytorch that referenced this pull request Nov 24, 2026
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.
ZhaoqiongZ added a commit to ZhaoqiongZ/pytorch that referenced this pull request Nov 27, 2026
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.
pytorchmergebot pushed a commit to ZhaoqiongZ/pytorch that referenced this pull request Nov 28, 2026
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.
pytorchmergebot pushed a commit to ZhaoqiongZ/pytorch that referenced this pull request Nov 30, 2026
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.
pytorchmergebot pushed a commit to ZhaoqiongZ/pytorch that referenced this pull request Dec 2, 2026
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.
pytorchmergebot pushed a commit to ZhaoqiongZ/pytorch that referenced this pull request Dec 4, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants