diff --git a/README.rst b/README.rst index dab86a8..e2bbc5f 100644 --- a/README.rst +++ b/README.rst @@ -40,6 +40,8 @@ Usage >>> telegram: --telegram_id=CHAT_ID Id of telegram chat + --telegram_thread_id=CHAT_THREAD_ID + Id of telegram thread --telegram_token=BOT_TOKEN Telegram Bot token --telegram_report_url=URL diff --git a/pytest_telegram/plugin.py b/pytest_telegram/plugin.py index ab4bdf1..01dd734 100644 --- a/pytest_telegram/plugin.py +++ b/pytest_telegram/plugin.py @@ -19,6 +19,13 @@ def pytest_addoption(parser): default=None, help='Id of telegram chat' ) + group.addoption( + '--telegram_thread_id', + action='store', + dest='telegram_thread_id', + default=None, + help='Id of telegram thread' + ) group.addoption( '--telegram_token', action='store', @@ -87,6 +94,7 @@ def pytest_terminal_summary(terminalreporter, exitstatus, config): token = config.option.telegram_token telegram_uri = f'https://api.telegram.org/bot{token}' chat_id = config.option.telegram_id + thread_id = config.option.telegram_thread_id success_sticker_id = config.option.success_sticker_id fail_sticker_id = config.option.fail_sticker_id @@ -134,6 +142,8 @@ def pytest_terminal_summary(terminalreporter, exitstatus, config): 'text': f'{final_results}{time_taken}{custom_text}{report_url}\n{failed_tests}{error_tests}', 'reply_to_message_id': message_id } + if thread_id: + message_payload['message_thread_id'] = thread_id requests.post(f'{telegram_uri}/sendMessage', json=message_payload).json() except exceptions.RequestException as e: LOG.error("TELEGRAM Sending Message Error!!!")