test: refactor plugin to use parameter not envvar
What changed, and why it matters
This commit is a test-only cleanup. It changes a single test plugin and its corresponding test to pass a setting as a normal plugin option instead of reading it from an environment variable. There is no change to production code, no security fix, and no vulnerability.
No action needed; this is a benign test refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies tests/plugins/feature-test.py and tests/test_plugin.py. The plugin no longer imports os or calls os.getenv(‘PLUGIN_DISABLE’); instead it registers a bool option ‘disable-on-init’ and checks options.get(‘disable-on-init’). The test removes the monkeypatch.setenv call and passes disable-on-init=True as a node option. This is purely a refactoring of test internals.
Changed components
tests/plugins/feature-test.pytests/test_plugin.pyInspect captured patch +4 / −6
diff --git a/tests/plugins/feature-test.py b/tests/plugins/feature-test.py
index 45900216..37f27fc2 100755
--- a/tests/plugins/feature-test.py
+++ b/tests/plugins/feature-test.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python3
from pyln.client import Plugin
-import os
# Register a different set feature of feature bits for each location so we can
# later check that they are being passed correctly.
@@ -15,10 +14,10 @@ plugin = Plugin(
@plugin.init()
def init(configuration, options, plugin):
- disable = os.getenv("PLUGIN_DISABLE")
- if disable:
+ if options.get('disable-on-init'):
return {'disable': 'init saying disable'}
return {}
+plugin.add_option('disable-on-init', False, 'disable plugin on init', opt_type='bool')
plugin.run()
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index fa9137e9..a9345140 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -1748,7 +1748,7 @@ def test_plugin_feature_announce(node_factory):
assert node['features'] == expected_node_features(extra=[203])
-def test_plugin_feature_remove(node_factory, monkeypatch):
+def test_plugin_feature_remove(node_factory):
"""Check that features registered by plugins get removed if a plugin
disables itself.
@@ -1759,9 +1759,8 @@ def test_plugin_feature_remove(node_factory, monkeypatch):
- 1 << 205 for bolt11 invoices
"""
- monkeypatch.setenv("PLUGIN_DISABLE", "1")
plugin = os.path.join(os.path.dirname(__file__), 'plugins/feature-test.py')
- l1 = node_factory.get_node(options={'plugin': plugin})
+ l1 = node_factory.get_node(options={'plugin': plugin, 'disable-on-init': True})
# Check that we don't include the features set in getmanifest.
our_feats = l1.rpc.getinfo()["our_features"]
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.