From 93ac98db224a05825d8d848390f919ecb7dbf70d Mon Sep 17 00:00:00 2001
From: Matt Whitlock <c-lightning@mattwhitlock.name>
Date: Sat, 23 Aug 2025 02:19:15 -0400
Subject: [PATCH] tests: skip certain tests if RUST is not enabled

 * tests/test_cln_lsps.py::test_lsps0_listprotocols
 * tests/test_clnrest.py
 * tests/test_connection.py::test_wss_proxy

Changelog-Fixed: pytest: Tests that require Rust no longer fail if Rust is disabled.
---
 contrib/pyln-testing/pyln/testing/utils.py | 1 +
 tests/test_cln_lsps.py                     | 4 ++++
 tests/test_cln_rs.py                       | 4 ++--
 tests/test_clnrest.py                      | 8 +++++++-
 tests/test_connection.py                   | 3 ++-
 5 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py
index 2317c96c315fe76cd22ce438e145e3f33cecb3f1..e841268396d90808cdb8dace8e7605e690c023e7 100644
--- a/contrib/pyln-testing/pyln/testing/utils.py
+++ b/contrib/pyln-testing/pyln/testing/utils.py
@@ -82,6 +82,7 @@ def env(name, default=None):
 EXPERIMENTAL_DUAL_FUND = env("EXPERIMENTAL_DUAL_FUND", "0") == "1"
 EXPERIMENTAL_SPLICING = env("EXPERIMENTAL_SPLICING", "0") == "1"
 GENERATE_EXAMPLES = env("GENERATE_EXAMPLES", "0") == "1"
+RUST = env("RUST", "0") == "1"
 
 
 def wait_for(success, timeout=TIMEOUT):
diff --git a/tests/test_cln_lsps.py b/tests/test_cln_lsps.py
index 68ae13792b0747ac1d95c31240eaab526cea4477..28f09d64d750491e5244f6e52414747fbfcc998c 100644
--- a/tests/test_cln_lsps.py
+++ b/tests/test_cln_lsps.py
@@ -1,5 +1,8 @@
 from fixtures import *  # noqa: F401,F403
+from pyln.testing.utils import RUST
+
 import os
+import unittest
 
 RUST_PROFILE = os.environ.get("RUST_PROFILE", "debug")
 
@@ -15,6 +18,7 @@ def test_lsps_service_disabled(node_factory):
     l1.daemon.is_in_log("`lsps-service` not enabled")
 
 
+@unittest.skipUnless(RUST, 'RUST is not enabled')
 def test_lsps0_listprotocols(node_factory):
     l1, l2 = node_factory.get_nodes(2, opts=[
         {}, {"dev-lsps-service": True}
diff --git a/tests/test_cln_rs.py b/tests/test_cln_rs.py
index 6363e78304582b3415239af85c5aaea9d0419472..dec0800f44edf7541055ee3dfe5430b26245eb74 100644
--- a/tests/test_cln_rs.py
+++ b/tests/test_cln_rs.py
@@ -1,7 +1,7 @@
 from fixtures import *  # noqa: F401,F403
 from pathlib import Path
 from pyln import grpc as clnpb
-from pyln.testing.utils import env, TEST_NETWORK, wait_for, sync_blockheight, TIMEOUT, RpcError
+from pyln.testing.utils import RUST, TEST_NETWORK, wait_for, sync_blockheight, TIMEOUT, RpcError
 from utils import first_scid
 import grpc
 import pytest
@@ -11,7 +11,7 @@
 
 # Skip the entire module if we don't have Rust.
 pytestmark = pytest.mark.skipif(
-    env('RUST') != '1',
+    not RUST,
     reason='RUST is not enabled skipping rust-dependent tests'
 )
 
diff --git a/tests/test_clnrest.py b/tests/test_clnrest.py
index f9c14a28a985caafa2f689953a3e75ad5a42d4f3..ece1f813b0525a85804ec79a62fa0fec015fe31d 100644
--- a/tests/test_clnrest.py
+++ b/tests/test_clnrest.py
@@ -1,5 +1,5 @@
 from fixtures import *  # noqa: F401,F403
-from pyln.testing.utils import TEST_NETWORK, wait_for
+from pyln.testing.utils import RUST, TEST_NETWORK, wait_for
 from pyln.client import Millisatoshi
 import requests
 from pathlib import Path
@@ -10,6 +10,12 @@
 import pytest
 import json
 
+# Skip the entire module if we don't have Rust.
+pytestmark = pytest.mark.skipif(
+    not RUST,
+    reason='RUST is not enabled; skipping Rust-dependent tests'
+)
+
 
 def http_session_with_retry():
     # All requests are done after matching "REST server running" in the log,
diff --git a/tests/test_connection.py b/tests/test_connection.py
index ed81c75f52d472d40eff31f2eaec35ab1204b808..dd7bed0b17e50d26e69b078e372d27bdc3ce1316 100644
--- a/tests/test_connection.py
+++ b/tests/test_connection.py
@@ -12,7 +12,7 @@
     mine_funding_to_announce, first_scid,
     CHANNEL_SIZE
 )
-from pyln.testing.utils import SLOW_MACHINE, VALGRIND, EXPERIMENTAL_DUAL_FUND, FUNDAMOUNT
+from pyln.testing.utils import SLOW_MACHINE, VALGRIND, EXPERIMENTAL_DUAL_FUND, FUNDAMOUNT, RUST
 
 import os
 import pytest
@@ -4563,6 +4563,7 @@ def test_last_stable_connection(node_factory):
     assert only_one(l2.rpc.listpeerchannels()['channels'])['last_stable_connection'] >= recon_time + STABLE_TIME
 
 
+@unittest.skipUnless(RUST, 'RUST is not enabled')
 def test_wss_proxy(node_factory):
     wss_port = node_factory.get_unused_port()
     ws_port = node_factory.get_unused_port()
