Skip to content

Commit 142a35c

Browse files
Skip tests using PyTorch JIT on Python 3.14+
1 parent 5b8bd57 commit 142a35c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

test/test_pytorch.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23
import unittest
34

45
import torch
@@ -7,19 +8,24 @@
78
from fickling.fickle import Pickled
89
from fickling.pytorch import PyTorchModelWrapper
910

11+
_lacks_torch_jit_support = sys.version_info >= (3, 14)
1012

1113
class TestPyTorchModule(unittest.TestCase):
1214
def setUp(self):
1315
model = models.mobilenet_v2()
1416
self.filename_v1_3 = "test_model.pth"
1517
torch.save(model, self.filename_v1_3)
1618
self.zip_filename = "test_random_data.zip"
17-
m = torch.jit.script(model)
18-
self.torchscript_filename = "test_model_torchscript.pth"
19-
torch.jit.save(m, self.torchscript_filename)
19+
if not _lacks_torch_jit_support:
20+
m = torch.jit.script(model)
21+
self.torchscript_filename = "test_model_torchscript.pth"
22+
torch.jit.save(m, self.torchscript_filename)
2023

2124
def tearDown(self):
22-
for filename in [self.filename_v1_3, self.zip_filename, self.torchscript_filename]:
25+
files = [self.filename_v1_3, self.zip_filename]
26+
if not _lacks_torch_jit_support:
27+
files.append(self.torchscript_filename)
28+
for filename in files:
2329
if os.path.exists(filename):
2430
os.remove(filename)
2531

@@ -29,6 +35,7 @@ def test_wrapper(self):
2935
except Exception as e: # noqa
3036
self.fail(f"PyTorchModelWrapper was not able to load a PyTorch v1.3 file: {e}")
3137

38+
@unittest.skipIf(_lacks_torch_jit_support, "PyTorch 2.9.1 JIT broken with Python 3.14+")
3239
def test_torchscript_wrapper(self):
3340
try:
3441
PyTorchModelWrapper(self.torchscript_filename)
@@ -40,6 +47,7 @@ def test_pickled(self):
4047
pickled_portion = result.pickled
4148
self.assertIsInstance(pickled_portion, Pickled)
4249

50+
@unittest.skipIf(_lacks_torch_jit_support, "PyTorch 2.9.1 JIT broken with Python 3.14+")
4351
def test_torchscript_pickled(self):
4452
result = PyTorchModelWrapper(self.torchscript_filename)
4553
pickled_portion = result.pickled

0 commit comments

Comments
 (0)