jeudi 21 juin 2018

Python unittest with xmlrunner

Good evening. Have the small problem with python unittest. I need to output tests results to xml file. I did that, but a lost the console outputing. Need to copy results in console + xml output. How can a do that?

import json
import requests
import unittest
import configparser
import xmlrunner

class Test(unittest.TestCase):

 def test_User(self):
    config = configparser.ConfigParser()
    config.read('..//settings.ini')
    config.sections()
    url = config['API']['url'] + 'user/temp'
    print('\n---User - temp registration---' + '\nURL: ' + url)
    headers = {'Content-type': 'application/json',
               'Accept': 'text/plain',
               'Content-Encoding': 'utf-8'}
    data = {"deviceId": "1",
            "idfa": "1",
            "gaid": "1"}
    post(data, url, headers)

#Post request
def post(data, url, headers):
   print('Request: ' + str(data))
   answer = requests.post(url, data=json.dumps(data), headers=headers)
   print(str(answer) + '\nResponse: ' + str(answer.json()))

if __name__ == "__main__":
   with open('results.xml', 'wb') as output:
    unittest.main(
        testRunner=xmlrunner.XMLTestRunner(output=output),
        failfast=False, buffer=False, catchbreak=False)

Test results with xmlrunner.

Test results without xmlrunner.

Need both results: console output + xml output

Aucun commentaire:

Enregistrer un commentaire