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

Unclear usage

Open ailjushkin opened this issue 8 years ago • 4 comments

I am trying to use your module to get some data from testrail.

I have a use-case:

  1. get a test run
  2. get all cases from this test run
  3. filter them by a certain criteria (custom attribute)

How can I do this?

ailjushkin avatar Feb 01 '17 11:02 ailjushkin

Here is how I do it in my test runner: (where self._tr is an instance of the testrail client, self._tr = TestRail(...))

    def _start_run(self, project_id, regression, smoke, run_name):
        # Get project from testrail
        project = self._tr.project(project_id)

        # Get suites associated with that project
        suites = self._tr.suites()

        # Get test cases for each suite
        cases = list()
        for suite in suites:
            cases.extend(list(self._tr.cases(suite)))

        # Groom out those not flagged as regression
        # This is specific to my project structure, but you get the idea
        if regression:
            cases = [case for case in cases if case.regression]

        # Groom out those not flagged as smoke
        if smoke:
            cases = [case for case in cases if case.smoke]

        # Instantiate a new run
        new_run = self._tr.run()
        new_run.name = run_name
        new_run.project = project
        new_run.cases = cases
        new_run.include_all = False

        # Send the new run to TestRail, which creates the run
        run = self._tr.add(new_run)  # This adds all test cases to run by default

leviable avatar Feb 01 '17 13:02 leviable

Getting the test run is somewhat hard to answer because you can have testrail configured in multiple ways. So you may need to write some code filtering on one or more of plans, milestones, and suites to get the specific run you want.

Currently we don't have direct support for custom attributes but it will be coming soon (1-2 months). You however you should be able to hack it doing something like this:

cases = filter(lambda c: c.raw_data()['your_custom_field'] == 'foo', run.cases)

If you hare having issues getting the run let us know more about how you have testrail structured.

travispavek avatar Feb 01 '17 13:02 travispavek

Ignore my comment. We do have custom field support! Look at levi's example.

So if you have a custom field called "foo" you can get it by calling case.foo.

travispavek avatar Feb 01 '17 13:02 travispavek

Actually, ignore my use of case.regression and case.smoke. I'm actually doing some behind-the-scenes trickery to make that work. Your lambda suggestion is best.

leviable avatar Feb 01 '17 13:02 leviable