fundakol / pytest-jira-xray

Plugin for pytest to upload test results to JIRA XRAY
Apache License 2.0
27 stars 18 forks source link

Close execution issue after upload #89

Open RicardoM17 opened 1 year ago

RicardoM17 commented 1 year ago

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 :smile: !

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 :sweat_smile:

fundakol commented 1 year ago

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?

RicardoM17 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.