Skip to content

Commit

Permalink
pabotlib on by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorpela committed Nov 30, 2024
1 parent d1c768e commit 5360cc2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
19 changes: 18 additions & 1 deletion src/pabot/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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('--'):
Expand All @@ -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":
Expand Down Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions tests/test_pabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 5360cc2

Please sign in to comment.