@@ -82,8 +82,7 @@ def setup_mock_for_logging(mock_client_init):
8282
8383@mock .patch (REPORT_PORTAL_SERVICE )
8484def test_basic (mock_client_init ):
85- mock_client = setup_mock (mock_client_init )
86- setup_mock_for_logging (mock_client_init )
85+ mock_client = setup_mock_for_logging (mock_client_init )
8786 result = utils .run_pytest_tests (tests = ["examples/bdd/step_defs/test_arguments.py" ])
8887 assert int (result ) == 0 , "Exit code should be 0 (no errors)"
8988
@@ -124,8 +123,7 @@ def test_basic(mock_client_init):
124123
125124@mock .patch (REPORT_PORTAL_SERVICE )
126125def test_basic_with_feature_suite (mock_client_init ):
127- mock_client = setup_mock (mock_client_init )
128- setup_mock_for_logging (mock_client_init )
126+ mock_client = setup_mock_for_logging (mock_client_init )
129127 variables = {"rp_hierarchy_code" : True }
130128 variables .update (utils .DEFAULT_VARIABLES .items ())
131129 result = utils .run_pytest_tests (tests = ["examples/bdd/step_defs/test_arguments.py" ], variables = variables )
@@ -189,8 +187,7 @@ def test_feature_descriptions(mock_client_init):
189187
190188@mock .patch (REPORT_PORTAL_SERVICE )
191189def test_failed_feature (mock_client_init ):
192- mock_client = setup_mock (mock_client_init )
193- setup_mock_for_logging (mock_client_init )
190+ mock_client = setup_mock_for_logging (mock_client_init )
194191 result = utils .run_pytest_tests (tests = ["examples/bdd/step_defs/test_failed_step.py" ])
195192 assert int (result ) == 1 , "Exit code should be 1 (test error)"
196193
@@ -224,8 +221,7 @@ def test_failed_feature(mock_client_init):
224221
225222@mock .patch (REPORT_PORTAL_SERVICE )
226223def test_scenario_attributes (mock_client_init ):
227- mock_client = setup_mock (mock_client_init )
228- setup_mock_for_logging (mock_client_init )
224+ mock_client = setup_mock_for_logging (mock_client_init )
229225
230226 test_file = "examples/bdd/step_defs/test_belly.py"
231227 result = utils .run_pytest_tests (tests = [test_file ])
@@ -241,8 +237,7 @@ def test_scenario_attributes(mock_client_init):
241237
242238@mock .patch (REPORT_PORTAL_SERVICE )
243239def test_feature_attributes (mock_client_init ):
244- mock_client = setup_mock (mock_client_init )
245- setup_mock_for_logging (mock_client_init )
240+ mock_client = setup_mock_for_logging (mock_client_init )
246241
247242 variables = {"rp_hierarchy_code" : True }
248243 variables .update (utils .DEFAULT_VARIABLES .items ())
@@ -268,8 +263,7 @@ def test_feature_attributes(mock_client_init):
268263
269264@mock .patch (REPORT_PORTAL_SERVICE )
270265def test_background_step (mock_client_init ):
271- mock_client = setup_mock (mock_client_init )
272- setup_mock_for_logging (mock_client_init )
266+ mock_client = setup_mock_for_logging (mock_client_init )
273267
274268 test_file = "examples/bdd/step_defs/test_background.py"
275269 result = utils .run_pytest_tests (tests = [test_file ])
@@ -332,8 +326,7 @@ def test_background_step(mock_client_init):
332326
333327@mock .patch (REPORT_PORTAL_SERVICE )
334328def test_background_two_steps (mock_client_init ):
335- mock_client = setup_mock (mock_client_init )
336- setup_mock_for_logging (mock_client_init )
329+ mock_client = setup_mock_for_logging (mock_client_init )
337330
338331 test_file = "examples/bdd/step_defs/test_background_two_steps.py"
339332 result = utils .run_pytest_tests (tests = [test_file ])
@@ -379,8 +372,7 @@ def test_background_two_steps(mock_client_init):
379372@pytest .mark .skipif (pytest_bdd_version [0 ] < 8 , reason = "Only for pytest-bdd 8+" )
380373@mock .patch (REPORT_PORTAL_SERVICE )
381374def test_rule (mock_client_init ):
382- mock_client = setup_mock (mock_client_init )
383- setup_mock_for_logging (mock_client_init )
375+ mock_client = setup_mock_for_logging (mock_client_init )
384376 result = utils .run_pytest_tests (tests = ["examples/bdd/step_defs/test_rule_steps.py" ])
385377 assert int (result ) == 0 , "Exit code should be 0 (no errors)"
386378
@@ -474,8 +466,7 @@ def test_rule(mock_client_init):
474466@pytest .mark .skipif (pytest_bdd_version [0 ] < 8 , reason = "Only for pytest-bdd 8+" )
475467@mock .patch (REPORT_PORTAL_SERVICE )
476468def test_rule_hierarchy (mock_client_init ):
477- mock_client = setup_mock (mock_client_init )
478- setup_mock_for_logging (mock_client_init )
469+ mock_client = setup_mock_for_logging (mock_client_init )
479470
480471 variables = {"rp_hierarchy_code" : True }
481472 variables .update (utils .DEFAULT_VARIABLES .items ())
@@ -899,8 +890,7 @@ def test_scenario_outline_dynamic_name(mock_client_init):
899890
900891@mock .patch (REPORT_PORTAL_SERVICE )
901892def test_scenario_outline_fail (mock_client_init ):
902- mock_client = setup_mock (mock_client_init )
903- setup_mock_for_logging (mock_client_init )
893+ mock_client = setup_mock_for_logging (mock_client_init )
904894 result = utils .run_pytest_tests (tests = ["examples/bdd/step_defs/scenario_outline_fail_steps.py" ])
905895 assert int (result ) == 1 , "Exit code should be 1 (test error)"
906896
@@ -1094,3 +1084,48 @@ def test_custom_test_case_id(mock_client_init):
10941084 finish_calls = mock_client .finish_test_item .call_args_list
10951085 for call in finish_calls :
10961086 assert call [1 ]["status" ] == "PASSED"
1087+
1088+
1089+ @mock .patch (REPORT_PORTAL_SERVICE )
1090+ def test_rp_tests_attributes_rule (mock_client_init ):
1091+ mock_client = setup_mock (mock_client_init )
1092+ variables = {"rp_tests_attributes" : "test_key:test_value" }
1093+ variables .update (utils .DEFAULT_VARIABLES .items ())
1094+ result = utils .run_pytest_tests (
1095+ tests = ["examples/bdd/step_defs/test_rule_description_steps.py" ], variables = variables
1096+ )
1097+ assert int (result ) == 0 , "Exit code should be 0 (no errors)"
1098+
1099+ scenario_call = mock_client .start_test_item .call_args_list [0 ]
1100+ assert scenario_call [1 ]["attributes" ] == [{"key" : "test_key" , "value" : "test_value" }]
1101+
1102+
1103+ @pytest .mark .parametrize ("rp_hierarchy_code, scenario_idx" , [(True , 2 ), (False , 0 )])
1104+ @mock .patch (REPORT_PORTAL_SERVICE )
1105+ def test_rp_tests_attributes_rule_hierarchy (mock_client_init , rp_hierarchy_code , scenario_idx ):
1106+ mock_client = setup_mock (mock_client_init )
1107+ variables = {"rp_tests_attributes" : "test_key:test_value" , "rp_hierarchy_code" : rp_hierarchy_code }
1108+ variables .update (utils .DEFAULT_VARIABLES .items ())
1109+ result = utils .run_pytest_tests (
1110+ tests = ["examples/bdd/step_defs/test_rule_description_steps.py" ], variables = variables
1111+ )
1112+ assert int (result ) == 0 , "Exit code should be 0 (no errors)"
1113+
1114+ scenario_call = mock_client .start_test_item .call_args_list [scenario_idx ]
1115+ assert scenario_call [1 ]["attributes" ] == [{"key" : "test_key" , "value" : "test_value" }]
1116+
1117+
1118+ @mock .patch (REPORT_PORTAL_SERVICE )
1119+ def test_rp_tests_attributes_bdd_tags (mock_client_init ):
1120+ mock_client = setup_mock (mock_client_init )
1121+ variables = {"rp_tests_attributes" : "test_key:test_value" }
1122+ variables .update (utils .DEFAULT_VARIABLES .items ())
1123+ result = utils .run_pytest_tests (tests = ["examples/bdd/step_defs/test_belly.py" ], variables = variables )
1124+ assert int (result ) == 0 , "Exit code should be 0 (no errors)"
1125+
1126+ scenario_call = mock_client .start_test_item .call_args_list [0 ]
1127+ attributes = scenario_call [1 ]["attributes" ]
1128+ assert len (attributes ) == 3
1129+ assert {"key" : "test_key" , "value" : "test_value" } in attributes
1130+ assert {"value" : "ok" } in attributes
1131+ assert {"key" : "key" , "value" : "value" } in attributes
0 commit comments