gurock / trcli

TR CLI (trcli) is a command line tool for interacting with TestRail.
Mozilla Public License 2.0
47 stars 42 forks source link

Refs not updated for existing cases on junitxml record_property invocation #127

Open romedtino opened 1 year ago

romedtino commented 1 year ago

TestRail CLI Version

1.4.2

CLI Environment

Mac OS Ventura 13.1, Python 3.11.1

TestRail Version

6.6.1.1166

TestRail Instance Type

Enterprise Server

Current behavior

In a pytest junitxml generated report, having property testrail_case_field value refs:REF-123 will not update the references of a case if it exists. If the case does not exist, trcli creates the test case and will contain the reference.

Desired behavior

Having property with refs should update existing cases

More Details

I currently have a very basic pytest script that uses --case-matcher property to match case IDs and if a given case exists, having record_property("testrail_case_field", "refs:PRJCT-1234") fails to add the reference to the existing case.

Sample pytest script - name to test_sample.py

def test_sample_existing(record_property):
    record_property("test_id", "C1234")
    record_property("testrail_case_field", "refs:PRJCT-1234")
    assert 5 == 5

def test_sample_not_existing(record_property):
    record_property("testrail_case_field", "refs:PRJCT-1234")
    assert 5 == 5

running with pytest --juinitxml "junit-report.xml" generates something like-

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
   <testsuite name="pytest" errors="0" failures="0" skipped="0" tests="2" time="0.034" timestamp="2023-02-16T10:09:08.765432" hostname="MYCOMPUTER">
      <testcase classname="test_tr" name="test_sample_existing" time="0.001">
         <properties>
            <property name="test_id" value="C1234" />
            <property name="testrail_case_field" value="refs:PRJCT-1234" />
         </properties>
      </testcase>
      <testcase classname="test_tr" name="test_sample_not_existing" time="0.001">
         <properties>
            <property name="testrail_case_field" value="refs:PRJCT-1234" />
         </properties>
      </testcase>
   </testsuite>
</testsuites>

Then invoking trcli with it

trcli -y -h https://mytestrail.instance.com --project "My Project" --username "username" --password "password" parse_junit --case-matcher "property" --title "My Run" -f junit-report.xml

It reports success and when I look at the TestRail site, I see it add a new testcase for test_sample_not_existing with the correct References but when I look at case C1234, the Reference value is still None. Is this expected behavior for cases that exist that you can't update refs through a test run? Thanks!

d-rede commented 1 year ago

Hello @romedtino

Updating test cases is not currently supported by the TestRail CLI, but thanks for raising this issue. I'll tag it as an enhancement to be potentially analyzed for a future release.

Cheers

romedtino commented 1 year ago

No problem. If anyone is interested, I kludged source and modified trcli/trcli/api/api_request_handler.py where I add this tidbit in line 305

                        if test_case["case_fields"]:
                            new_refs = test_case["case_fields"]["refs"]
                            if new_refs != case["refs"]:
                                payload = {
                                    "case_id": case["id"],
                                    "refs": new_refs
                                }
                                response = self.client.send_post(f"update_case/{case['id']}", payload)
                                print(response)

This will override refs if the new one coming in is different from what existed.

skats-neogov commented 5 months ago

No problem. If anyone is interested, I kludged source and modified trcli/trcli/api/api_request_handler.py where I add this tidbit in line 305

                        if test_case["case_fields"]:
                            new_refs = test_case["case_fields"]["refs"]
                            if new_refs != case["refs"]:
                                payload = {
                                    "case_id": case["id"],
                                    "refs": new_refs
                                }
                                response = self.client.send_post(f"update_case/{case['id']}", payload)
                                print(response)

This will override refs if the new one coming in is different from what existed.

Maybe create a PR and owners can merge so we can all benefit. I have exact same problem.

romedtino commented 5 months ago

I unfortunately don't work for the company I did this for anymore. Though I do still keep in contact with old coworkers that might be willing to do just that. But the source is up there and I'm not 100% convinced it's the best approach. It probably needs more brains, how to deal with existing, append/overwrite, cli options? šŸ¤·