Skip to content

Commit fc999d5

Browse files
authored
Merge pull request #1013 from launchableinc/error-msg-improvement
Error message improvement
2 parents a66ff5a + 1662508 commit fc999d5

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

launchable/commands/subset.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ class Optimize(TestPathWriter):
363363

364364
def __init__(self, app: Application):
365365
self.rest = rest
366+
self.input_given = False # set to True when an attempt was made to add to self.test_paths
366367
self.test_paths: List[List[Dict[str, str]]] = []
367368
self.output_handler = self._default_output_handler
368369
self.exclusion_output_handler = self._default_exclusion_output_handler
@@ -381,20 +382,21 @@ def _default_exclusion_output_handler(self, subset: List[TestPath], rest: List[T
381382
self.output_handler(rest, subset)
382383

383384
def test_path(self, path: TestPathLike):
385+
"""register one test"""
386+
384387
def rel_base_path(path):
385388
if isinstance(path, str):
386389
return pathlib.Path(file_path_normalizer.relativize(path)).as_posix()
387390
else:
388391
return path
389392

393+
self.input_given = True
390394
if isinstance(path, str) and any(s in path for s in ('*', "?")):
391395
for i in glob.iglob(path, recursive=True):
392396
if os.path.isfile(i):
393397
self.test_paths.append(self.to_test_path(rel_base_path(i)))
394-
return
395-
396-
"""register one test"""
397-
self.test_paths.append(self.to_test_path(rel_base_path(path)))
398+
else:
399+
self.test_paths.append(self.to_test_path(rel_base_path(path)))
398400

399401
def stdin(self) -> Union[TextIO, List]:
400402
# To avoid the cli continue to wait from stdin
@@ -441,6 +443,8 @@ def scan(self, base: str, pattern: str,
441443
- if a TestPath is returned, that's added as is
442444
"""
443445

446+
self.input_given = True
447+
444448
if path_builder is None:
445449
# default implementation of path_builder creates a file name relative to `source` so as not
446450
# to be affected by the path
@@ -511,11 +515,11 @@ def get_payload(
511515
def run(self):
512516
"""called after tests are scanned to compute the optimized order"""
513517
if not is_get_tests_from_previous_sessions and len(self.test_paths) == 0:
514-
click.echo(
515-
click.style(
516-
"ERROR: subset candidates are empty. Please set subset candidates or use `--get-tests-from-previous-sessions` option", # noqa E501
517-
fg="red"),
518-
err=True)
518+
if self.input_given:
519+
msg = "ERROR: Given arguments did not match any tests. They appear to be incorrect/non-existent." # noqa E501
520+
else:
521+
msg = "ERROR: Expecting tests to be given, but none provided. See https://www.launchableinc.com/docs/features/predictive-test-selection/requesting-and-running-a-subset-of-tests/subsetting-with-the-launchable-cli/ and provide ones, or use the `--get-tests-from-previous-sessions` option" # noqa E501
522+
click.echo(click.style(msg, fg="red"), err=True)
519523
exit(1)
520524

521525
# When Error occurs, return the test name as it is passed.

tests/commands/test_subset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def test_subset_with_get_tests_from_previous_full_runs(self):
289289
# check error when input candidates are empty without --get-tests-from-previous-sessions option
290290
result = self.cli("subset", "--target", "30%", "--session", self.session, "file")
291291
self.assert_exit_code(result, 1)
292-
self.assertTrue("Please set subset candidates or use `--get-tests-from-previous-sessions` option" in result.stdout)
292+
self.assertIn("use the `--get-tests-from-previous-sessions` option", result.stdout)
293293

294294
responses.replace(
295295
responses.POST,

0 commit comments

Comments
 (0)