diff --git a/launchable/commands/helper.py b/launchable/commands/helper.py index f485f7690..d13108dd3 100644 --- a/launchable/commands/helper.py +++ b/launchable/commands/helper.py @@ -16,6 +16,7 @@ def find_or_create_session( is_observation: bool = False, links: List[str] = [], is_no_build: bool = False, + lineage: Optional[str] = None, ) -> Optional[str]: """Determine the test session ID to be used. @@ -28,6 +29,11 @@ def find_or_create_session( Args: session: The --session option value build_name: The --build option value + flavor: The --flavor option values + is_observation: The --observation value + links: The --link option values + is_no_build: The --no-build option value + lineage: lineage option value """ from .record.session import session as session_command @@ -45,6 +51,7 @@ def find_or_create_session( is_observation=is_observation, links=links, is_no_build=is_no_build, + lineage=lineage, ) saved_build_name = read_build() return read_session(str(saved_build_name)) @@ -83,6 +90,7 @@ def find_or_create_session( is_observation=is_observation, links=links, is_no_build=is_no_build, + lineage=lineage, ) return read_session(saved_build_name) diff --git a/launchable/commands/record/session.py b/launchable/commands/record/session.py index 8c7642649..06b86ec15 100644 --- a/launchable/commands/record/session.py +++ b/launchable/commands/record/session.py @@ -82,6 +82,14 @@ def _validate_session_name(ctx, param, value): metavar='SESSION_NAME', callback=_validate_session_name, ) +@click.option( + '--lineage', + 'lineage', + help='Set lineage name. A lineage is a set of test sessions grouped and this option value will be used for a lineage name.', + required=False, + type=str, + metavar='LINEAGE', +) @click.pass_context def session( ctx: click.core.Context, @@ -93,6 +101,7 @@ def session( links: List[str] = [], is_no_build: bool = False, session_name: Optional[str] = None, + lineage: Optional[str] = None, ): """ print_session is for backward compatibility. @@ -132,6 +141,7 @@ def session( "flavors": flavor_dict, "isObservation": is_observation, "noBuild": is_no_build, + "lineage": lineage, } _links = capture_link(os.environ) diff --git a/launchable/commands/record/tests.py b/launchable/commands/record/tests.py index 2b7d37dcb..502acd58f 100644 --- a/launchable/commands/record/tests.py +++ b/launchable/commands/record/tests.py @@ -143,6 +143,14 @@ def _validate_group(ctx, param, value): type=str, metavar='SESSION_NAME', ) +@click.option( + '--lineage', + 'lineage', + help='Set lineage name. This option value will be passed to the record session command if a session isn\'t created yet.', + required=False, + type=str, + metavar='LINEAGE', +) @click.pass_context def tests( context: click.core.Context, @@ -158,7 +166,8 @@ def tests( is_allow_test_before_build: bool, links: List[str] = [], is_no_build: bool = False, - session_name: Optional[str] = None + session_name: Optional[str] = None, + lineage: Optional[str] = None, ): logger = Logger() @@ -200,7 +209,8 @@ def tests( session=session, build_name=build_name, flavor=flavor, - links=links)) + links=links, + lineage=lineage)) build_name = read_build() record_start_at = get_record_start_at(session_id, client) diff --git a/launchable/commands/subset.py b/launchable/commands/subset.py index 7a11200f0..b77ef5159 100644 --- a/launchable/commands/subset.py +++ b/launchable/commands/subset.py @@ -141,6 +141,14 @@ help="If you want to only send test reports, please use this option", is_flag=True, ) +@click.option( + '--lineage', + 'lineage', + help='Set lineage name. This option value will be passed to the record session command if a session isn\'t created yet.', + required=False, + type=str, + metavar='LINEAGE', +) @click.pass_context def subset( context: click.core.Context, @@ -161,6 +169,7 @@ def subset( ignore_flaky_tests_above: Optional[float], links: List[str] = [], is_no_build: bool = False, + lineage: Optional[str] = None, ): if is_observation and is_get_tests_from_previous_sessions: @@ -180,6 +189,7 @@ def subset( is_observation=is_observation, links=links, is_no_build=is_no_build, + lineage=lineage ) file_path_normalizer = FilePathNormalizer(base_path, no_base_path_inference=no_base_path_inference) diff --git a/tests/commands/record/test_session.py b/tests/commands/record/test_session.py index e9ea9b05a..fe0029451 100644 --- a/tests/commands/record/test_session.py +++ b/tests/commands/record/test_session.py @@ -27,7 +27,11 @@ def test_run_session_without_flavor(self): self.assertEqual(result.exit_code, 0) payload = json.loads(responses.calls[0].request.body.decode()) - self.assert_json_orderless_equal({"flavors": {}, "isObservation": False, "links": [], "noBuild": False}, payload) + self.assert_json_orderless_equal( + {"flavors": {}, + "isObservation": False, "links": [], + "noBuild": False, "lineage": None}, + payload) @responses.activate @mock.patch.dict(os.environ, { @@ -49,6 +53,7 @@ def test_run_session_with_flavor(self): "isObservation": False, "links": [], "noBuild": False, + "lineage": None, }, payload) with self.assertRaises(ValueError): @@ -68,7 +73,11 @@ def test_run_session_with_observation(self): payload = json.loads(responses.calls[0].request.body.decode()) - self.assert_json_orderless_equal({"flavors": {}, "isObservation": True, "links": [], "noBuild": False}, payload) + self.assert_json_orderless_equal( + {"flavors": {}, + "isObservation": True, "links": [], + "noBuild": False, "lineage": None}, + payload) @responses.activate @mock.patch.dict(os.environ, { @@ -99,4 +108,27 @@ def test_run_session_with_session_name(self): self.assertEqual(result.exit_code, 0) payload = json.loads(responses.calls[2].request.body.decode()) - self.assert_json_orderless_equal({"flavors": {}, "isObservation": False, "links": [], "noBuild": False}, payload) + self.assert_json_orderless_equal( + {"flavors": {}, + "isObservation": False, "links": [], + "noBuild": False, "lineage": None}, + payload) + + @responses.activate + @mock.patch.dict(os.environ, { + "LAUNCHABLE_TOKEN": CliTestCase.launchable_token, + 'LANG': 'C.UTF-8', + }, clear=True) + def test_run_session_with_lineage(self): + result = self.cli("record", "session", "--build", self.build_name, + "--lineage", "example-lineage") + self.assertEqual(result.exit_code, 0) + + payload = json.loads(responses.calls[0].request.body.decode()) + self.assert_json_orderless_equal({ + "flavors": {}, + "isObservation": False, + "links": [], + "noBuild": False, + "lineage": "example-lineage", + }, payload)