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

Close execution issue after upload #89

Open
RicardoM17 opened this issue Aug 22, 2023 · 5 comments
Open

Close execution issue after upload #89

RicardoM17 opened this issue Aug 22, 2023 · 5 comments
Labels
question Further information is requested

Comments

@RicardoM17
Copy link

RicardoM17 commented Aug 22, 2023

Hello again @fundakol ,

I was wondering if it's possible to close an execution issue after the results have been uploaded, either by default or with a flag.

I'm not sure if this is something that this plugin supports or aims to do so, or if one should do it manually/directly with Jira. I guess in that sense one would need to use also what is in #8 .

Apologies for the issues but hopefully these help other people in the future as well.

Thank you once again 😄 !

Edit: In case it's not clear I'm talking about the Jira Execution status, not the PASS, FAILED etc, i.e. in my case a new execution issue is created but it is left in state New. I would like to have it moved to Done immediately as these are generated automatically, so in my case nobody would close them.

I can maybe get around to this by having an Automation within Jira itself, but ideally this wouldn't be needed and it seems like this would be a nice addition to this project.

Edit 2:
Having checked https://docs.getxray.app/display/XRAYCLOUD/Using+Xray+JSON+format+to+import+execution+results it seems that this is not supported on XRAY's side. I'll still wait to hear from you either way 😅

@fundakol
Copy link
Owner

This plugin does not do this, it even does not know about any issues associated with a test in Jira. It just send blindly to Xray what it found in results.
But can you set your Jira up to automatically close an issue if test assigned to it has passed?

@fundakol fundakol added the question Further information is requested label Aug 22, 2023
@RicardoM17
Copy link
Author

@fundakol Thank you once again for the quick reply.

Having investigated a bit more it seems that unfortunately this is not easily achieved/possible with Cloud Jira + XRAY as the XRAY fields are not available in Smart values JSON at all (only for Server). That being said, I understand that this is outside the scope of this project so I will find alternative options.

Maybe I can do it directly with the hook that you suggested:

@pytest.hookimpl(trylast=True)
def pytest_sessionfinish(session):
    xray_plugin = session.config.pluginmanager.getplugin('JIRA_XRAY')
    execution_id = xray_plugin.issue_id
    # send call to close issue

In any case, thank you for the help :)

Feel free to close this issue, (I'll keep it open unless you still want to add something to the discussion).

@fundakol
Copy link
Owner

If you don't want to create a new execution issue you can create one and provide it's id in CLI, so results will be updated for this issue.

pytest --jira-xray --execution IssueId

@RicardoM17
Copy link
Author

No that's fine. I will be creating a ton of them automatically based on CI pipelines so I need them to create new ones every time.

I managed to do it with the snippet that I provided above. However pytest_sessionfinish is called both when the test results are being imported to XRAY, but also when the tests are executed (which on my side are two different commands).

I get around this by checking

    if not xray_plugin or not xray_plugin.issue_id:
        return

However maybe you know of a better way.

I thought about doing the transition in pytest_xray_results(results,session) instead, but there while I do have a session, I can't get nothing in xray_plugin = session.config.pluginmanager.getplugin('JIRA_XRAY') and so I can't get the issue_id. Does this make sense?

@fundakol
Copy link
Owner

You can write execution id in to a file (in pytest_sessionfinish) and have another Python's script which can be executed after pytest. This script can look for the file and if exists read issue id from it and send request to xray to close the issue.
This script can be much more complex, for example you can check if all tests passed an then close the issue, otherwise you can keep it open for further investigation.

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

No branches or pull requests

2 participants