allankp / pytest-testrail

pytest plugin for integration with TestRail, for creating testruns and updating results
MIT License
95 stars 125 forks source link

New Testrail Version Has Broken This Plugin #151

Open glazeb opened 3 years ago

glazeb commented 3 years ago

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']

JohnOSu commented 3 years ago

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

glazeb commented 3 years ago

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

glazeb commented 3 years ago

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
JohnOSu commented 3 years ago

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

`

chayanmazumder-cpi commented 2 years ago

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

AudioLeaf commented 2 years ago

@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.

allankp commented 2 years ago

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

chayanmazumder-cpi commented 2 years ago

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

Miracle05 commented 2 years ago

@allankp repo now obsoleted and unsupported?