Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ConfigArgParse instead of argparse, to support getting parameters from config file and/or env vars. #1167

Merged
merged 8 commits into from
Nov 25, 2019
16 changes: 8 additions & 8 deletions locust/test/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import os
import tempfile

from locust.main import parse_options

Expand Down Expand Up @@ -35,14 +36,13 @@ def test_skip_log_setup(self):
self.assertEqual(opts.skip_log_setup, True)

def test_parameter_parsing(self):
conf_file = '/tmp/locust.conf'
os.environ['LOCUST_LOCUSTFILE'] = "locustfile_from_env"
with open(conf_file, 'w') as file:
file.write("host host_from_config\nweb-host webhost_from_config\n")
parser, _ = parse_options(default_config_files=['/tmp/locust.conf'])
options = parser.parse_args(['-H','host_from_args'])
del os.environ['LOCUST_LOCUSTFILE'] # remove this so it doesnt impact later tests
os.remove(conf_file)
with tempfile.NamedTemporaryFile(mode='w') as file:
os.environ['LOCUST_LOCUSTFILE'] = "locustfile_from_env"
file.write("host host_from_config\nweb-host webhost_from_config")
file.flush()
parser, _ = parse_options(default_config_files=[file.name])
options = parser.parse_args(['-H','host_from_args'])
del os.environ['LOCUST_LOCUSTFILE']
self.assertEqual(options.web_host, 'webhost_from_config')
self.assertEqual(options.locustfile, 'locustfile_from_env')
self.assertEqual(options.host, 'host_from_args') # overridden
5 changes: 3 additions & 2 deletions locust/test/test_zmqrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class ZMQRPC_tests(LocustTestCase):
def setUp(self):
super(ZMQRPC_tests, self).setUp()
self.server = zmqrpc.Server('*', 0)
self.server = zmqrpc.Server('127.0.0.1', 0)
self.client = zmqrpc.Client('localhost', self.server.port, 'identity')

def tearDown(self):
Expand Down Expand Up @@ -40,7 +40,8 @@ def test_client_recv(self):
self.assertEqual(msg.node_id, 'identity')

def test_client_retry(self):
server = zmqrpc.Server('0.0.0.0', 8888)
# use non-zero port this time, just to increase code coverage
server = zmqrpc.Server('127.0.0.1', 8888)
cyberw marked this conversation as resolved.
Show resolved Hide resolved
server.socket.close()
with self.assertRaises(zmq.error.ZMQError):
server.recv_from_client()