From 2bdb7358878a8f1e2405b1f5c3e7938d54a67759 Mon Sep 17 00:00:00 2001 From: Tingyu Wang Date: Fri, 3 Nov 2023 15:20:32 -0400 Subject: [PATCH] Skip certain `cugraph-pyg` tests when torch-sparse is not available (#3970) A follow-up PR to fix the test failure again on rockylinux (see [log](https://github.com/rapidsai/cugraph/actions/runs/6718664898/job/18258783035#step:7:9297)). `import_optional` only catches `ModuleNotFoundError`, however, it threw an `OSError` on rockylinux. Let's just catch all exceptions during imports in this case. Closes https://github.com/rapidsai/graph_dl/issues/373 Authors: - Tingyu Wang (https://github.com/tingyu66) Approvers: - Rick Ratzel (https://github.com/rlratzel) - Brad Rees (https://github.com/BradReesWork) URL: https://github.com/rapidsai/cugraph/pull/3970 --- .../cugraph_pyg/tests/test_cugraph_loader.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/python/cugraph-pyg/cugraph_pyg/tests/test_cugraph_loader.py b/python/cugraph-pyg/cugraph_pyg/tests/test_cugraph_loader.py index 836b30c9df7..853836dc2a6 100644 --- a/python/cugraph-pyg/cugraph_pyg/tests/test_cugraph_loader.py +++ b/python/cugraph-pyg/cugraph_pyg/tests/test_cugraph_loader.py @@ -29,9 +29,15 @@ torch = import_optional("torch") torch_geometric = import_optional("torch_geometric") -torch_sparse = import_optional("torch_sparse") trim_to_layer = import_optional("torch_geometric.utils.trim_to_layer") +try: + import torch_sparse # noqa: F401 + + HAS_TORCH_SPARSE = True +except: # noqa: E722 + HAS_TORCH_SPARSE = False + @pytest.mark.skipif(isinstance(torch, MissingModule), reason="torch not available") def test_cugraph_loader_basic(karate_gnn): @@ -201,9 +207,7 @@ def test_cugraph_loader_from_disk_subset(): @pytest.mark.skipif(isinstance(torch, MissingModule), reason="torch not available") -@pytest.mark.skipif( - isinstance(torch_sparse, MissingModule), reason="torch-sparse not available" -) +@pytest.mark.skipif(not HAS_TORCH_SPARSE, reason="torch-sparse not available") def test_cugraph_loader_from_disk_subset_csr(): m = [2, 9, 99, 82, 11, 13] n = torch.arange(1, 1 + len(m), dtype=torch.int32) @@ -336,9 +340,7 @@ def test_cugraph_loader_e2e_coo(): @pytest.mark.skipif(isinstance(torch, MissingModule), reason="torch not available") -@pytest.mark.skipif( - isinstance(torch_sparse, MissingModule), reason="torch-sparse not available" -) +@pytest.mark.skipif(not HAS_TORCH_SPARSE, reason="torch-sparse not available") @pytest.mark.parametrize("framework", ["pyg", "cugraph-ops"]) def test_cugraph_loader_e2e_csc(framework): m = [2, 9, 99, 82, 9, 3, 18, 1, 12]