Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter tests when testplan option is provided #113

Open
sanderploegsma opened this issue Jun 11, 2024 · 1 comment
Open

Filter tests when testplan option is provided #113

sanderploegsma opened this issue Jun 11, 2024 · 1 comment

Comments

@sanderploegsma
Copy link
Contributor

When working with a large collection of tests and multiple test plans, it would make sense if this plugin was able to filter the tests based on whether they are part of the provided Xray test plan.

I can think of two ways of supporting this:

  1. Query the Xray API to get a list of test ids for a given test plan
  2. Add a pytest marker to each test with the test plans that contain it

The first option is more versatile as it doesn't require keeping the test decorators in sync with Xray, but it also adds some complexity to handle cases when querying the API fails.

@fundakol
Copy link
Owner

My intention writing this plugin wasn't to implement Rest API for Jira/Xray except the one for uploading results. Also I don't use Xray anymore so I am not able to test this plugin with new features. But if you want to implement this feature and test it with your Jira server that's fine for me.

Probably this may look like that:

def pytest_collection_modifyitems(config, items):
    if not (test_plan_id := config.option.testplan):
        return
    selected_items = []
    deselected_items = []
    selected_tests: set[str] = get_tests_for_testplan(test_plan_id)
    for item in items:
        if marker := item.get_closest_marker('xray'):
            if set(marker.args).issubset(test_plan_id):
                selected_items.append(item)
            else:                
                deselected_items.append(item)                                
        else:
            selected_items.append(item)  # run other tests without xray marker
    if deselected_items:
        config.hook.pytest_deselected(items=deselected_items)
    items[:] = selected_items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants