lundi 27 juillet 2020

Is it possible to name individual subtests in python unittest (HtmlTestRunner)?

py version:Python 3.6.3

Context: I am using HtmlTestRunner with unittest to get tidy post-deployment test reports for a REST API.

Issue: When I run the tests, I do get everything separated, but the subtests inherit their name 1:1 from the test.

Example view in html: Example view in html with errors

Example code :

import unittest
import HtmlTestRunner

class testBadRequest(unittest.TestCase):
    def test_serviceOne_bad_request(self):
        with self.subTest():
            x = endpointOne.getAll(acfg_url, cfg.badHeaders, acfg_host, acfg_params)
            self.assertEqual(x["status_code"], 400)
        with self.subTest():
            x = endpointOne.getByID(cfg.badID, acfg_url, acfg_headers, acfg_host, acfg_params)
            self.assertEqual(x["status_code"], 400)
            
if __name__ == '__main__':
    unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(combine_reports=True)) 

Aucun commentaire:

Enregistrer un commentaire