From 5360cc2f0747869a8138bbc4c5fe5e0bf4f54140 Mon Sep 17 00:00:00 2001 From: Mikko Korpela Date: Sat, 30 Nov 2024 16:25:26 +0200 Subject: [PATCH] pabotlib on by default --- README.md | 12 ++++++++---- src/pabot/arguments.py | 19 ++++++++++++++++++- tests/test_pabot.py | 19 +++++++++++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 139f770c..cf52902f 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ There are several ways you can help in improving this tool: ## Command-line options pabot [--verbose|--testlevelsplit|--command .. --end-command| - --processes num|--pabotlib|--pabotlibhost host|--pabotlibport port| + --processes num|--no-pabotlib|--pabotlibhost host|--pabotlibport port| --processtimeout num| --shard i/n| --artifacts extensions|--artifactsinsubfolders| @@ -83,8 +83,11 @@ Supports all [Robot Framework command line options](https://robotframework.org/r Special option "all" will use as many processes as there are executable suites or tests. ---pabotlib - Start PabotLib remote server. This enables locking and resource distribution between parallel test executions. +PabotLib remote server is started by default to enable locking and resource distribution +between parallel test executions. + +--no-pabotlib + Disable the PabotLib remote server if you don't need locking or resource distribution features. --pabotlibhost [HOSTNAME] Host name of the PabotLib remote server (default is 127.0.0.1) @@ -142,8 +145,9 @@ Example usages: pabot --command java -jar robotframework.jar --end-command --include SMOKE tests pabot --processes 10 tests pabot --pabotlibhost 192.168.1.123 --pabotlibport 8271 --processes 10 tests - pabot --pabotlib --pabotlibhost 192.168.1.111 --pabotlibport 8272 --processes 10 tests pabot --artifacts png,mp4,txt --artifactsinsubfolders directory_to_tests + # To disable PabotLib: + pabot --no-pabotlib tests ### PabotLib diff --git a/src/pabot/arguments.py b/src/pabot/arguments.py index 0400214c..bba8d5cb 100644 --- a/src/pabot/arguments.py +++ b/src/pabot/arguments.py @@ -80,7 +80,7 @@ def _parse_pabot_args(args): # type: (List[str]) -> Tuple[List[str], Dict[str, "verbose": False, "help": False, "testlevelsplit": False, - "pabotlib": False, + "pabotlib": True, "pabotlibhost": "127.0.0.1", "pabotlibport": 8270, "processes": _processes_count(), @@ -113,6 +113,10 @@ def _parse_pabot_args(args): # type: (List[str]) -> Tuple[List[str], Dict[str, remaining_args = [] i = 0 + # Track conflicting options during parsing + saw_pabotlib_flag = False + saw_no_pabotlib = False + while i < len(args): arg = args[i] if not arg.startswith('--'): @@ -121,6 +125,16 @@ def _parse_pabot_args(args): # type: (List[str]) -> Tuple[List[str], Dict[str, continue arg_name = arg[2:] # Strip '--' + + if arg_name == "no-pabotlib": + saw_no_pabotlib = True + pabot_args["pabotlib"] = False # Just set the main flag + args = args[1:] + continue + if arg_name == "pabotlib": + saw_pabotlib_flag = True + args = args[1:] + continue # Special case for command if arg_name == "command": @@ -166,6 +180,9 @@ def _parse_pabot_args(args): # type: (List[str]) -> Tuple[List[str], Dict[str, remaining_args.append(arg) i += 1 + if saw_pabotlib_flag and saw_no_pabotlib: + raise DataError("Cannot use both --pabotlib and --no-pabotlib options together") + pabot_args["argumentfiles"] = argumentfiles return remaining_args, pabot_args diff --git a/tests/test_pabot.py b/tests/test_pabot.py index 06130a03..faaa8382 100644 --- a/tests/test_pabot.py +++ b/tests/test_pabot.py @@ -1372,6 +1372,25 @@ def test_parse_args_command_with_pabot_args(self): self.assertEqual(pabot_args["command"], ["script.sh", "--processes", "5"]) self.assertEqual(pabot_args["verbose"], True) + def test_pabotlib_defaults_to_enabled(self): + options, _, pabot_args, _ = arguments.parse_args(["suite"]) + self.assertTrue(pabot_args["pabotlib"]) + self.assertFalse("no_pabotlib" in pabot_args) # Ensure internal flag not leaked + + def test_no_pabotlib_disables_pabotlib(self): + options, _, pabot_args, _ = arguments.parse_args(["--no-pabotlib", "suite"]) + self.assertFalse(pabot_args["pabotlib"]) + self.assertFalse("no_pabotlib" in pabot_args) # Ensure internal flag not leaked + + def test_pabotlib_option_shows_warning(self): + options, _, pabot_args, _ = arguments.parse_args(["--pabotlib", "suite"]) + self.assertTrue(pabot_args["pabotlib"]) + self.assertFalse("no_pabotlib" in pabot_args) # Ensure internal flag not leaked + + def test_conflicting_pabotlib_options_raise_error(self): + with self.assertRaises(DataError) as context: + arguments.parse_args(["--pabotlib", "--no-pabotlib", "suite"]) + self.assertIn("Cannot use both --pabotlib and --no-pabotlib", str(context.exception)) if __name__ == "__main__": unittest.main()