pytest-testrail icon indicating copy to clipboard operation
pytest-testrail copied to clipboard

New Testrail Version Has Broken This Plugin

Open glazeb opened this issue 3 years ago • 9 comments

Describe the bug When we try to send test results to testrail using this plugin it no longer runs any tests and throws an error (below). It seems Testrail's newest version has caused this issue based on our findings as they added to their response for getting tests.

image

To Reproduce Steps to reproduce the behavior: Just try to send results to testrail and you should see the error.

Fix we tried locally and worked Below is the file and method we updated to make it work. The last part is what is needed to be added when returning response (['tests']).

Plugin.py

class PyTestRailPlugin(object):

def get_tests(self, run_id): """ :return: the list of tests containing in a testrun. """ response = self.client.send_get( GET_TESTS_URL.format(run_id), cert_check=self.cert_check ) error = self.client.get_error(response) if error: print('[{}] Failed to get tests: "{}"'.format(TESTRAIL_PREFIX, error)) return None return response['tests']

glazeb avatar Sep 21 '21 13:09 glazeb

That won't necessarily get all the tests, for example - if there are more than 250 tests in the target.

The changes described here have now been implemented: https://discuss.gurock.com/t/bulk-api-endpoint-changes-coming-soon/19537

These calls now need to be able to handle the paginated responses: get_cases get_runs get_results get_tests get_results_for_case get_results_for_run get_plans get_projects get_sections get_milestones get_history_for_case get_attachments_for_case get_attachments_for_run Get_attachments_for_plan

JohnOSu avatar Sep 21 '21 14:09 JohnOSu

Does anyone know if this stuff is being worked on already?

glazeb avatar Sep 21 '21 16:09 glazeb

So for the pagination stuff it would have to be written something like this correct?

def get_tests(self, run_id): """ :return: the list of tests containing in a testrun. """ response = self.client.send_get(GET_TESTS_URL.format(run_id), cert_check=self.cert_check) error = self.client.get_error(response) if error: print('[{}] Failed to get tests: "{}"'.format(TESTRAIL_PREFIX, error)) return None

test_cases = response["cases"]

while response["size"] == 250:
    pagination_suffix_url = (response["_links"]["next"]).replace('/api/v2/', "")
    response = self.client.send_get(pagination_suffix_url, cert_check=self.cert_check)
    if error:
        print('[{}] Failed to get tests: "{}"'.format(TESTRAIL_PREFIX, error))
        return None
    
    test_cases = test_cases + response["cases"]

return test_cases

glazeb avatar Sep 21 '21 18:09 glazeb

I have no idea if this is still being maintained. This worked for me:

`

def get_tests(self, run_id):
    """
    :return: the list of tests containing in a testrun.

    """
    from urllib.parse import parse_qsl, urlencode

    master_test_list = []
    repeat = True
    params = None

    while repeat:
        uri = GET_TESTS_URL.format(run_id)
        if params:
            uri = uri+params
        response = self.client.send_get(uri, cert_check=self.cert_check)

        error = self.client.get_error(response)
        if error:
            print('[{}] Failed to get tests: "{}"'.format(TESTRAIL_PREFIX, error))
            return None

        test_list = [item for item in response['tests']]
        master_test_list.extend(test_list)

        repeat = response['_links']['next']
        if repeat:
            params = f'&{urlencode(parse_qsl(repeat))}'

    return master_test_list

`

JohnOSu avatar Sep 21 '21 18:09 JohnOSu

This is a blocker, and anyone looking at it? Cause we have virtual env in prod, and cannot create hot fix to run this.

chayanmazumder-cpi avatar Sep 28 '21 03:09 chayanmazumder-cpi

@chayanmazumder-cpi I implemented the solution outlined by @JohnOSu in my own pip package.

I've noticed there are lingering pull requests on this repo so I'm not sure if a PR for this would ever make it in as I cannot tell if the project is still being maintained.

So if you need an immediate solution I'd try what John did. Hope this helps.

AudioLeaf avatar Sep 30 '21 22:09 AudioLeaf

Hi, I don't have a massive amount of spare time. But a PR would certainly be looked at.

allankp avatar Oct 21 '21 15:10 allankp

@allankp what test to run and how-to, before raising a PR?

chayanmazumder-cpi avatar Oct 27 '21 05:10 chayanmazumder-cpi

@allankp repo now obsoleted and unsupported?

Miracle05 avatar Nov 07 '21 12:11 Miracle05