Sonar code issue for python programming

@pytest.mark.e2e
    def test_007_mobile_schedule_tc_no_timeslot(self, request, config, env,
                                                   gather_issue_flag):
        tc_name = request.node.originalname
        tc_run = TriggerTest()
        skip_true = {
            hp.MANUAL_STEPS_BULLETED_LIST: 0,
            hp.ISSUE_RESOLVED: 1
        }
        skip_false = {
            hp.MANUAL_STEPS_CONNECTION_CHECK: 0,
            hp.CONFIRM_STEP_TURN_OFF_WIFI: 0,
            hp.CONFIRM_STEP_REBOOT_MODEM: 0,
            hp.ISSUE_RESOLVED: 0,
            hp.CONFIRM_STEP_TO_AGENT: 0
        }
        test_param = {"tc_name": tc_name, "site_id": "1", "account_number": "33007",
                      **"config": config, "env": env, "skip_true":skip_true,**
**                      "skip_false":skip_false,"workflow": self.workflow, "channel_name": self.channel_name,**
**                      "device_type": self.device_type,**
**                      "failed": self.failed, "passed": self.passed,**
**                    "gather_issue_flag": gather_issue_flag}**
**        result_1 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_reboot_modem,**
**                    hp.confirm_fix_manual_reboot_modem, hp.final_feedback]**
**        result_2 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_check_cables,**
**                    hp.confirm_step_turn_off_wifi, hp.confirm_step_reboot_modem, hp.reboot_modem, hp.ping_modem,**
**                    hp.rediagnose, hp.confirm_fix_reboot_modem_ds, hp.check_before_schedule_tc,**
                    hp.confirm_step_to_agent_no_timeslot, hp.to_agent]
        tc_run.run_test_case(skip_result=result_1, wo_skip_result=result_2, **test_param)

    @pytest.mark.e2e
    def test_008_mobile_schedule_tc_existing_tc(self, request, config, env,
                                                        gather_issue_flag):
        tc_name = request.node.originalname
        tc_run = TriggerTest()
        skip_true = {
            hp.MANUAL_STEPS_BULLETED_LIST: 0,
            hp.ISSUE_RESOLVED: 1
        }
        skip_false = {
            hp.MANUAL_STEPS_CONNECTION_CHECK: 0,
            hp.CONFIRM_STEP_TURN_OFF_WIFI: 0,
            hp.CONFIRM_STEP_REBOOT_MODEM: 0,
            hp.ISSUE_RESOLVED: 0,
            hp.CONFIRM_STEP_TC_ALREADY_SCHEDULED: 0
        }
        test_param = {"tc_name": tc_name, "site_id": "1", "account_number": "33008",
                      **"config": config, "env": env, "skip_true":skip_true,**
**                      "skip_false":skip_false,"workflow": self.workflow, "channel_name": self.channel_name,**
**                      "device_type": self.device_type,**
**                      "failed": self.failed, "passed": self.passed,**
**                    "gather_issue_flag": gather_issue_flag}**
**        result_1 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_reboot_modem,**
**                    hp.confirm_fix_manual_reboot_modem, hp.final_feedback]**
**        result_2 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_check_cables,**
**                    hp.confirm_step_turn_off_wifi, hp.confirm_step_reboot_modem, hp.reboot_modem, hp.ping_modem,**
**                    hp.rediagnose, hp.confirm_fix_reboot_modem_ds, hp.check_before_schedule_tc,**
                    hp.confirm_step_tc_already_scheduled, hp.final_feedback]
        tc_run.run_test_case(skip_result=result_1, wo_skip_result=result_2, **test_param)

Highlighted lines are giving as duplicate.
but similar kind of lines used in other test cases also. but there it’s not giving any duplicate issue. For example,

@pytest.mark.e2e
    def test_006_mobile_poor_telemetry_(self, request, config, env,
                                                            gather_issue_flag):
        tc_name = request.node.originalname
        tc_run = TriggerTest()
        skip_true = {
            hp.MANUAL_STEPS_BULLETED_LIST: 0,
            hp.ISSUE_RESOLVED: 1
        }
        skip_false = {
            hp.MANUAL_STEPS_CONNECTION_CHECK: 0,
            hp.CONFIRM_STEP_TURN_OFF_WIFI: 0,
            hp.CONFIRM_STEP_REBOOT_MODEM: 0,
            hp.ISSUE_RESOLVED: 0,
            hp.OUTAGE:0
        }
        test_param = {"tc_name": tc_name, "site_id": "1", "account_number": "33003306",
                      "config": config, "env": env, "skip_true":skip_true,
                      "skip_false":skip_false,"workflow": self.workflow, "channel_name": self.channel_name,
                      "device_type": self.device_type,
                      "failed": self.failed, "passed": self.passed,
                    "gather_issue_flag": gather_issue_flag}
        result_1 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_reboot_modem,
                    hp.confirm_fix_manual_reboot_modem, hp.final_feedback]
        result_2 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_check_cables,
                    hp.confirm_step_turn_off_wifi, hp.confirm_step_reboot_modem,
                    hp.reboot_modem, hp.ping_modem, hp.rediagnose, hp.confirm_fix_reboot_modem_ds,
                    hp.check_before_schedule_tc, hp.notify_cust, hp.final_feedback]
        tc_run.run_test_case(skip_result=result_1, wo_skip_result=result_2, **test_param)

here, result_1 is same in above all 3 test cases.

could you please help me here. thank you…

Hi,

We ignore string literals in duplication detection, so there’s that. But even with the string literals, what’s marked duplicated in your screenshot looks… pretty much identical to me.

 
Ann

Hi Ann,

Hope you’re doing well ! and Thank you for the reply.

yes it’s almost similar. But each dict(test_param) and lists are unique( result_1 and result_2). Still it detected as duplicate.

My surprise is if you check test_006_mobile_poor_telemetry is identical by these values.
I have total 10 test cases in the file. but it report only test 7 and test 8 are duplicated. it should say test 6 also duplicate right? but it didn’t say like that

"config": config, "env": env, "skip_true":skip_true,
                      "skip_false":skip_false,"workflow": self.workflow, "channel_name": self.channel_name,
                      "device_type": self.device_type,
                      "failed": self.failed, "passed": self.passed,
                    "gather_issue_flag": gather_issue_flag}
        ****result_1** = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_reboot_modem,**
**                    hp.confirm_fix_manual_reboot_modem, hp.final_feedback]**

It should say all the result_1 are duplicate right? since all are same in my file.

will it say only if 8-10 lines of code are identical to next function as duplicate. do we have any condition like that ?

Could you please guide me here, thank you

Hi,

Sorry, I’m a little lost, and there’s too little here to really judge by.

Can you provide the full file?

 
Ann

Hi,

yea, sure. Please check this.

import pytest
from tests.automation.tests.trigger_run_test_case import TriggerTest
import tests.automation.tests.test_step_helpers as hp

@pytest.mark.e2e
class GetProdConfigTests:
    workflow = "CLAS_NO1"
    passed = "pass"
    failed = "fail"
    channel_name = "NEL-ZEM"
    device_type = "auto"

    @pytest.mark.e2e
    def test_001_token_next_tmt_ds_to_agent(self, request, config, env,gather_issue_flag):
        tc_name = request.node.originalname
        tc_run = TriggerTest()
        skip_true ={
                    hp.MANUAL_STEPS_BULLETED_LIST: 0,
                    hp.ISSUE_RESOLVED: 1
                }
        skip_false={
                    hp.MANUAL_STEPS_CONNECTION_CHECK: 0,
                    hp.CONFIRM_STEP_TURN_OFF_WIFI: 0,
                    hp.CONFIRM_STEP_REBOOT_MODEM: 0,
                    hp.ISSUE_RESOLVED: 0,
                    hp.CONFIRM_STEP_SCHEDULE_TC: 0,
                    hp.CONFIRM_STEP_SCHEDULE_NOTICE_CHARGE: 0,
                    hp.CONFIRM_STEP_TO_AGENT: 1
                }
        test_param = {"tc_name":tc_name, "site_id":"1", "account_number":"35308301",
                      "config":config, "env":env, "skip_true":skip_true,
                      "skip_false":skip_false,"workflow": self.workflow, "channel_name": self.channel_name,
                      "device_type": self.device_type,
                      "failed": self.failed, "passed": self.passed,
                    "gather_issue_flag": gather_issue_flag}
        result_1 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_reboot_modem,
                    hp.confirm_fix_manual_reboot_modem, hp.final_feedback]
        result_2 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_check_cables, hp.confirm_step_turn_off_wifi,
                    hp.confirm_step_reboot_modem, hp.reboot_modem, hp.ping_modem, hp.rediagnose,
                    hp.confirm_fix_reboot_modem_ds, hp.check_before_schedule_tc, hp.confirm_step_schedule_tc,
                    hp.confirm_step_schedule_notice_charge_new, hp.confirm_step_to_agent_schedule_tc, hp.final_feedback]
        tc_run.run_test_case(skip_result=result_1,wo_skip_result=result_2,**test_param)

    @pytest.mark.e2e
    def test_002_token_next_tmt_ds_arp_clear_positive(self, request, config, env, gather_issue_flag):
        tc_name = request.node.originalname
        tc_run = TriggerTest()
        skip_true = {
            hp.MANUAL_STEPS_BULLETED_LIST: 0,
            hp.ISSUE_RESOLVED: 1
        }
        skip_false = {
            hp.MANUAL_STEPS_CONNECTION_CHECK: 0,
            hp.CONFIRM_STEP_TURN_OFF_WIFI: 0,
            hp.CONFIRM_STEP_REBOOT_MODEM: 0,
            hp.ISSUE_RESOLVED: 1
        }
        test_param = {"tc_name": tc_name, "site_id": "1", "account_number": "33003302",
                      "config": config, "env": env, "skip_true":skip_true,
                      "skip_false":skip_false,"workflow": self.workflow, "channel_name": self.channel_name,
                      "device_type": self.device_type,
                      "failed": self.failed, "passed": self.passed,
                    "gather_issue_flag": gather_issue_flag}
        result_1 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_reboot_modem,
                    hp.confirm_fix_manual_reboot_modem, hp.final_feedback]
        result_2 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_check_cables, hp.confirm_step_turn_off_wifi,
                    hp.confirm_step_reboot_modem, hp.reboot_modem, hp.arp_clear, hp.ping_modem, hp.rediagnose,
                    hp.confirm_fix_reboot_modem_ds, hp.final_feedback]
        tc_run.run_test_case(skip_result=result_1, wo_skip_result=result_2, **test_param)

    @pytest.mark.e2e
    def test_003_token_next_tmt_ds_arp_clear_negative_manual_reboot(self, request, config, env, gather_issue_flag):
        tc_name = request.node.originalname
        tc_run = TriggerTest()
        skip_true = {
            hp.MANUAL_STEPS_BULLETED_LIST: 0,
            hp.ISSUE_RESOLVED: 1
        }
        skip_false = {
            hp.MANUAL_STEPS_CONNECTION_CHECK: 0,
            hp.CONFIRM_STEP_TURN_OFF_WIFI: 0,
            hp.CONFIRM_STEP_REBOOT_MODEM: 0,
            hp.CONFIRM_MANUAL_REBOOT_MODEM: 0,
            hp.MANUAL_STEPS_BULLETED_LIST:0,
            hp.ISSUE_RESOLVED:1
        }
        test_param = {"tc_name": tc_name, "site_id": "1", "account_number": "33003303",
                      "config": config, "env": env, "skip_true":skip_true,
                      "skip_false":skip_false,"workflow": self.workflow, "channel_name": self.channel_name,
                      "device_type": self.device_type,
                      "failed": self.failed, "passed": self.passed,
                    "gather_issue_flag": gather_issue_flag}
        result_1 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_reboot_modem,
                    hp.confirm_fix_manual_reboot_modem, hp.final_feedback]
        result_2 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_check_cables,
                    hp.confirm_step_turn_off_wifi, hp.confirm_step_reboot_modem, hp.reboot_modem, hp.arp_clear,
                    hp.confirm_step_manual_reboot_modem, hp.manual_reboot_modem, hp.confirm_fix_manual_reboot_modem,
                    hp.final_feedback]
        tc_run.run_test_case(skip_result=result_1, wo_skip_result=result_2, **test_param)

    @pytest.mark.e2e
    def test_004_token_schedule_tc_for_no_phone_number(self, request, config, env,
                                                                    gather_issue_flag):
        tc_name = request.node.originalname
        tc_run = TriggerTest()
        skip_true = {
            hp.MANUAL_STEPS_BULLETED_LIST: 0,
            hp.ISSUE_RESOLVED: 1
        }
        skip_false = {
            hp.MANUAL_STEPS_CONNECTION_CHECK: 0,
            hp.CONFIRM_STEP_TURN_OFF_WIFI: 0,
            hp.CONFIRM_STEP_REBOOT_MODEM: 0,
            hp.ISSUE_RESOLVED: 0,
            hp.CONFIRM_STEP_TO_AGENT:0
        }
        test_param = {"tc_name": tc_name, "site_id": "1", "account_number": "33003304",
                      "config": config, "env": env, "skip_true":skip_true,
                      "skip_false":skip_false,"workflow": self.workflow, "channel_name": self.channel_name,
                      "device_type": self.device_type,
                      "failed": self.failed, "passed": self.passed,
                    "gather_issue_flag": gather_issue_flag}
        result_1 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_reboot_modem,
                    hp.confirm_fix_manual_reboot_modem, hp.final_feedback]
        result_2 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_check_cables,
                    hp.confirm_step_turn_off_wifi, hp.confirm_step_reboot_modem, hp.reboot_modem,
                    hp.ping_modem, hp.rediagnose, hp.confirm_fix_reboot_modem_ds, hp.check_before_schedule_tc,
                    hp.confirm_step_to_agent_no_phone_number, hp.to_agent]
        tc_run.run_test_case(skip_result=result_1, wo_skip_result=result_2, **test_param)

    @pytest.mark.e2e
    def test_005_token_next_tmt_ds_reboot_modem_same_issue(self, request, config, env,
                                                            gather_issue_flag):
        tc_name = request.node.originalname
        tc_run = TriggerTest()
        skip_true = {
            hp.MANUAL_STEPS_BULLETED_LIST: 0,
            hp.ISSUE_RESOLVED: 1
        }
        skip_false = {
            hp.MANUAL_STEPS_CONNECTION_CHECK: 0,
            hp.CONFIRM_STEP_TURN_OFF_WIFI: 0,
            hp.CONFIRM_STEP_REBOOT_MODEM: 0,
            hp.ISSUE_RESOLVED: 0,
            hp.CONFIRM_STEP_TO_AGENT:0
        }
        test_param = {"tc_name": tc_name, "site_id": "1", "account_number": "33003305",
                      "config": config, "env": env, "skip_true":skip_true,
                      "skip_false":skip_false,"workflow": self.workflow, "channel_name": self.channel_name,
                      "device_type": self.device_type,
                      "failed": self.failed, "passed": self.passed,
                    "gather_issue_flag": gather_issue_flag}
        result_1 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_reboot_modem,
                    hp.confirm_fix_manual_reboot_modem,hp.check_before_schedule_tc,
                    hp.confirm_step_to_agent_same_issue,hp.to_agent]
        result_2 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_check_cables,
                    hp.confirm_step_turn_off_wifi, hp.confirm_step_reboot_modem, hp.reboot_modem, hp.ping_modem,
                    hp.rediagnose, hp.confirm_fix_reboot_modem_ds, hp.check_before_schedule_tc,
                    hp.confirm_step_to_agent_same_issue, hp.to_agent]
        tc_run.run_test_case(skip_result=result_1, wo_skip_result=result_2, **test_param)

    @pytest.mark.e2e
    def test_006_token_next_tmt_outage(self, request, config, env,
                                                            gather_issue_flag):
        tc_name = request.node.originalname
        tc_run = TriggerTest()
        skip_true = {
            hp.MANUAL_STEPS_BULLETED_LIST: 0,
            hp.ISSUE_RESOLVED: 1
        }
        skip_false = {
            hp.MANUAL_STEPS_CONNECTION_CHECK: 0,
            hp.CONFIRM_STEP_TURN_OFF_WIFI: 0,
            hp.CONFIRM_STEP_REBOOT_MODEM: 0,
            hp.ISSUE_RESOLVED: 0,
            hp.OUTAGE:0
        }
        test_param = {"tc_name": tc_name, "site_id": "1", "account_number": "33003306",
                      "config": config, "env": env, "skip_true":skip_true,
                      "skip_false":skip_false,"workflow": self.workflow, "channel_name": self.channel_name,
                      "device_type": self.device_type,
                      "failed": self.failed, "passed": self.passed,
                    "gather_issue_flag": gather_issue_flag}
        result_1 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_reboot_modem,
                    hp.confirm_fix_manual_reboot_modem, hp.final_feedback]
        result_2 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_check_cables,
                    hp.confirm_step_turn_off_wifi, hp.confirm_step_reboot_modem,
                    hp.reboot_modem, hp.ping_modem, hp.rediagnose, hp.confirm_fix_reboot_modem_ds,
                    hp.check_before_schedule_tc, hp.notify_cust, hp.final_feedback]
        tc_run.run_test_case(skip_result=result_1, wo_skip_result=result_2, **test_param)

    @pytest.mark.e2e
    def test_007_token_schedule_tc_for_no_timeslot(self, request, config, env,
                                                   gather_issue_flag):
        tc_name = request.node.originalname
        tc_run = TriggerTest()
        skip_true = {
            hp.MANUAL_STEPS_BULLETED_LIST: 0,
            hp.ISSUE_RESOLVED: 1
        }
        skip_false = {
            hp.MANUAL_STEPS_CONNECTION_CHECK: 0,
            hp.CONFIRM_STEP_TURN_OFF_WIFI: 0,
            hp.CONFIRM_STEP_REBOOT_MODEM: 0,
            hp.ISSUE_RESOLVED: 0,
            hp.CONFIRM_STEP_TO_AGENT: 0
        }
        test_param = {"tc_name": tc_name, "site_id": "1", "account_number": "33003307",
                      "config": config, "env": env, "skip_true":skip_true,
                      "skip_false":skip_false,"workflow": self.workflow, "channel_name": self.channel_name,
                      "device_type": self.device_type,
                      "failed": self.failed, "passed": self.passed,
                    "gather_issue_flag": gather_issue_flag}
        result_1 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_reboot_modem,
                    hp.confirm_fix_manual_reboot_modem, hp.final_feedback]
        result_2 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_check_cables,
                    hp.confirm_step_turn_off_wifi, hp.confirm_step_reboot_modem, hp.reboot_modem, hp.ping_modem,
                    hp.rediagnose, hp.confirm_fix_reboot_modem_ds, hp.check_before_schedule_tc,
                    hp.confirm_step_to_agent_no_timeslot, hp.to_agent]
        tc_run.run_test_case(skip_result=result_1, wo_skip_result=result_2, **test_param)

    @pytest.mark.e2e
    def test_008_token_schedule_tc_for_existing_tc(self, request, config, env,
                                                        gather_issue_flag):
        tc_name = request.node.originalname
        tc_run = TriggerTest()
        skip_true = {
            hp.MANUAL_STEPS_BULLETED_LIST: 0,
            hp.ISSUE_RESOLVED: 1
        }
        skip_false = {
            hp.MANUAL_STEPS_CONNECTION_CHECK: 0,
            hp.CONFIRM_STEP_TURN_OFF_WIFI: 0,
            hp.CONFIRM_STEP_REBOOT_MODEM: 0,
            hp.ISSUE_RESOLVED: 0,
            hp.CONFIRM_STEP_TC_ALREADY_SCHEDULED: 0
        }
        test_param = {"tc_name": tc_name, "site_id": "1", "account_number": "33003308",
                      "config": config, "env": env, "skip_true":skip_true,
                      "skip_false":skip_false,"workflow": self.workflow, "channel_name": self.channel_name,
                      "device_type": self.device_type,
                      "failed": self.failed, "passed": self.passed,
                    "gather_issue_flag": gather_issue_flag}
        result_1 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_reboot_modem,
                    hp.confirm_fix_manual_reboot_modem, hp.final_feedback]
        result_2 = [hp.GetEvents, hp.confirm_step_troubleshoot, hp.manual_check_cables,
                    hp.confirm_step_turn_off_wifi, hp.confirm_step_reboot_modem, hp.reboot_modem, hp.ping_modem,
                    hp.rediagnose, hp.confirm_fix_reboot_modem_ds, hp.check_before_schedule_tc,
                    hp.confirm_step_tc_already_scheduled, hp.final_feedback]
        tc_run.run_test_case(skip_result=result_1, wo_skip_result=result_2, **test_param)


Hi,

In fact, it looks like result_1 is identical for test_001, test_002, test_003, test_005, test_006, test_007 and test_008. And the first 3 lines of result_2 are identical for test_005, test_007 and test_008. At a glance, all the test_param arguments are identical if you ignore literal string values, which duplication detection does.

test_006 is not identical because of the difference between:
hp.reboot_modem, hp.ping_modem, hp.rediagnose, hp.confirm_fix_reboot_modem_ds,

and, from test_007:
hp.rediagnose, hp.confirm_fix_reboot_modem_ds, hp.check_before_schedule_tc,

I suppose there are subtle differences in ordering in everything but test_007 and test_008.

 
HTH,
Ann

Hi Ann,

Thank you for the detailed explanation. And sorry for the delay reply.
Based on your comments, I suppose if 10 lines are identical with other 10 lines then it’ll consider as duplicate. for example, result_1 is identical in all test cases but it didn’t mention as duplicate since it has only 2 lines.

Again thank you for your time

1 Like