pytest: Run plugin --help tests in the test directory

This is a followup to #2892. Since we now attempt to lock the PID file before
starting plugins we need to make sure that we actually use a unique lightning
directory for anything that attempts to call `--help`. If not we may be
conflicting with a `lightningd` that is running against that directory.

Notice that this still means that we will be unable to call `--help` on
`lightningd` if we have a running instance, but isolation in this case is
good, otherwise we'd be reading the default config anyway.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2019-08-05 19:07:45 +02:00 committed by ZmnSCPxj, ZmnSCPxj jxPCSmnZ
parent a2c00d42f2
commit e2f9a410f4

View File

@ -14,7 +14,7 @@ import time
import unittest import unittest
def test_option_passthrough(node_factory): def test_option_passthrough(node_factory, directory):
""" Ensure that registering options works. """ Ensure that registering options works.
First attempts without the plugin and then with the plugin. First attempts without the plugin and then with the plugin.
@ -23,12 +23,14 @@ def test_option_passthrough(node_factory):
help_out = subprocess.check_output([ help_out = subprocess.check_output([
'lightningd/lightningd', 'lightningd/lightningd',
'--lightning-dir={}'.format(directory),
'--help' '--help'
]).decode('utf-8') ]).decode('utf-8')
assert('--greeting' not in help_out) assert('--greeting' not in help_out)
help_out = subprocess.check_output([ help_out = subprocess.check_output([
'lightningd/lightningd', 'lightningd/lightningd',
'--lightning-dir={}'.format(directory),
'--plugin={}'.format(plugin_path), '--plugin={}'.format(plugin_path),
'--help' '--help'
]).decode('utf-8') ]).decode('utf-8')
@ -205,7 +207,7 @@ def test_plugin_connect_notifications(node_factory):
l2.daemon.wait_for_log(r'Received disconnect event') l2.daemon.wait_for_log(r'Received disconnect event')
def test_failing_plugins(): def test_failing_plugins(directory):
fail_plugins = [ fail_plugins = [
os.path.join(os.getcwd(), 'contrib/plugins/fail/failtimeout.py'), os.path.join(os.getcwd(), 'contrib/plugins/fail/failtimeout.py'),
os.path.join(os.getcwd(), 'contrib/plugins/fail/doesnotexist.py'), os.path.join(os.getcwd(), 'contrib/plugins/fail/doesnotexist.py'),
@ -215,6 +217,7 @@ def test_failing_plugins():
with pytest.raises(subprocess.CalledProcessError): with pytest.raises(subprocess.CalledProcessError):
subprocess.check_output([ subprocess.check_output([
'lightningd/lightningd', 'lightningd/lightningd',
'--lightning-dir={}'.format(directory),
'--plugin={}'.format(p), '--plugin={}'.format(p),
'--help', '--help',
]) ])