Skip to content

Commit

Permalink
Add test for main.parse_options()
Browse files Browse the repository at this point in the history
  • Loading branch information
heyman committed Nov 21, 2019
1 parent 989fa24 commit 009d104
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
version = locust.__version__


def parse_options():
def parse_options(args=None):
"""
Handle command-line options with argparse.ArgumentParser.
Expand Down Expand Up @@ -260,7 +260,7 @@ def parse_options():

# Finalize
# Return two-tuple of parser + the output from parse_args
return parser, parser.parse_args()
return parser, parser.parse_args(args=args)


def _is_package(path):
Expand Down
26 changes: 25 additions & 1 deletion locust/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ def __create_mock_locust_file(self, filename):
file.write(self.mock_locust_file_content)

def setUp(self):
pass
super(TestLoadLocustfile, self).setUp()

def tearDown(self):
os.remove(self.file_path)
super(TestLoadLocustfile, self).tearDown()

def test_load_locust_file_from_absolute_path(self):
self.__create_mock_locust_file('mock_locust_file.py')
Expand All @@ -96,3 +97,26 @@ def test_return_docstring_and_locusts(self):
self.assertEqual(docstring, self.mock_docstring)
self.assertIn('LocustSubclass', locusts)
self.assertNotIn('NotLocustSubclass', locusts)


class TestParseOptions(LocustTestCase):
def test_parse_options(self):
parser, options = main.parse_options(args=[
"-f", "locustfile.py",
"-c", "100",
"-r", "10",
"-t", "5m",
"--reset-stats",
"--stop-timeout", "5",
"MyLocustClass",
])
print("options:", options)
self.assertEqual("locustfile.py", options.locustfile)
self.assertEqual(100, options.num_clients)
self.assertEqual(10, options.hatch_rate)
self.assertEqual("5m", options.run_time)
self.assertTrue(options.reset_stats)
self.assertEqual(5, options.stop_timeout)
self.assertEqual(["MyLocustClass"], options.locust_classes)
# check default arg
self.assertEqual(8089, options.port)

0 comments on commit 009d104

Please sign in to comment.