mardi 26 mai 2015

Parsing unittest assertions to text file

Given a test suite:

class MyTestSuite(unittest.TestCase):

    def test_foo(self):
        self.assertLessEqual(temperature, boiling, "boiling will burn the cake")
        self.assertEqual(colour, 'golden brown', "the cake should be cooked until golden brown")

    def test_bar(self):
        self.assertIn('flour', ['flour', 'eggs'], "the flour should be mixed in with the eggs")

I would like to produce a text file describing all the assertions and tests. For example:

My Test Suite

Test foo:

* temperature <= boiling because boiling will burn the cake
* colour == 'golden brown' because the cake should be cooked until golden brown

Test bar:

* 'flour' in ['flour', 'eggs'] because the flour should be mixed in with the eggs

What is the best approach to parsing my test suite to file?

Possible solutions

  • Maybe there is already a package for this or maybe it's a trivial task through vanilla unittest, but my research hasn't found this.
  • Writing my own test runner which overrides each assertion to parse to a file (this isn't ideal as my test suites are using Selenium and take a long time to run).
  • Directly parse the python file as a text file, a huge amount of work.

Aucun commentaire:

Enregistrer un commentaire