allankp / pytest-testrail

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

How to get a run link after "End publishing" step? #86

Closed maksim-andr closed 5 years ago

maksim-andr commented 5 years ago

Hi! I need to use a link of run in any "finish hooks", e.g. "pytest_sessionfinish". This link must be sent to email or telegram bot. How can I get this link easily?

allankp commented 5 years ago

This is not something I would include in the plugin. You could add something to your own conftest or maybe if you are running in CI. Those normally have some sort of plugin that allows publishing to Telegram, Slack etc.

maksim-andr commented 5 years ago

I resolved this issue via pytest session:

def get_testrail_run_link(pytest_session):
    plugin_manager = pytest_session.config.pluginmanager
    if 'pytest-testrail-instance' in plugin_manager._name2plugin.keys():
        pti = plugin_manager._name2plugin['pytest-testrail-instance']
        run_id = pti.testrun_id
        testrail_api_url = pti.client._url
        testrail_url = testrail_api_url.split('?')[0]
        run_url = '{}?/runs/view/{}'.format(testrail_url, run_id)
        return run_url