unit test to capture output (python)

19 Views Asked by At

I would like help making a unit test that would capture the output of the jira description to ensure it has been printed. below is the code

from atlassian import Jira

API_KEY= "apikey123"
JIRA_URL= "https://name.atlassian.net/"
PROJECT_NAME = "SCRUM"

def access_jira_function():
    connection = Jira(
    url=JIRA_URL,
    username='[email protected]',
    password=API_KEY,cloud= True)

    response = connection.jql(f"project = {PROJECT_NAME}")
    for issue in response["issues"]:
    

   
    print(issue.keys())
    summary =issue["fields"]["summary"]
    description = issue["fields"]["description"]
    issue_id = issue["id"]
    print()
    print("issue#",issue_id)
    print(summary)
    print(description)

    


if __name__ == "__main__":
    access_jira_function()

so far i have tried:

import unittest
import sys
from io import StringIO

class testJira(unittest.TestCase):
    def test_print_output(description):
    captured_output = StringIO()
    sys.stdout = captured_output
    print(description)
    sys.stdout = sys.__stdout__
    return captured_output.getvalue().strip()

needless to say, when i run the test, it fails. any help would be appreciated

0

There are 0 best solutions below