From cf886e7dc41361b61df3d612d897963d4043c61d Mon Sep 17 00:00:00 2001 From: Wenqi Li <831580+wyli@users.noreply.github.com> Date: Wed, 1 Nov 2023 16:06:00 +0000 Subject: [PATCH] 5394 enable py311 tests (#7182) Fixes https://github.com/Project-MONAI/MONAI/issues/5394 ### Types of changes - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: Wenqi Li --- tests/utils.py | 54 ++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index 4bda8955ed..cf1711292f 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -724,22 +724,16 @@ def test_script_save(net, *inputs, device=None, rtol=1e-4, atol=0.0): """ # TODO: would be nice to use GPU if available, but it currently causes CI failures. device = "cpu" - try: - with tempfile.TemporaryDirectory() as tempdir: - convert_to_torchscript( - model=net, - filename_or_obj=os.path.join(tempdir, "model.ts"), - verify=True, - inputs=inputs, - device=device, - rtol=rtol, - atol=atol, - ) - except (RuntimeError, AttributeError): - if sys.version_info.major == 3 and sys.version_info.minor == 11: - warnings.warn("skipping py 3.11") - return - raise + with tempfile.TemporaryDirectory() as tempdir: + convert_to_torchscript( + model=net, + filename_or_obj=os.path.join(tempdir, "model.ts"), + verify=True, + inputs=inputs, + device=device, + rtol=rtol, + atol=atol, + ) def test_onnx_save(net, *inputs, device=None, rtol=1e-4, atol=0.0): @@ -753,23 +747,17 @@ def test_onnx_save(net, *inputs, device=None, rtol=1e-4, atol=0.0): # TODO: would be nice to use GPU if available, but it currently causes CI failures. device = "cpu" _, has_onnxruntime = optional_import("onnxruntime") - try: - with tempfile.TemporaryDirectory() as tempdir: - convert_to_onnx( - model=net, - filename=os.path.join(tempdir, "model.onnx"), - verify=True, - inputs=inputs, - device=device, - use_ort=has_onnxruntime, - rtol=rtol, - atol=atol, - ) - except (RuntimeError, AttributeError): - if sys.version_info.major == 3 and sys.version_info.minor == 11: - warnings.warn("skipping py 3.11") - return - raise + with tempfile.TemporaryDirectory() as tempdir: + convert_to_onnx( + model=net, + filename=os.path.join(tempdir, "model.onnx"), + verify=True, + inputs=inputs, + device=device, + use_ort=has_onnxruntime, + rtol=rtol, + atol=atol, + ) def download_url_or_skip_test(*args, **kwargs):