0

I have a unit test class that is a sub-class of python's unittest:

import unittest

class MyTestClass(unittest.TestCase):
    run_parameters = {param1: 'on'}
    def someTest(self):
        self.assertEquals(something, something_else)

Now I want to create a child class that modifies, say run_parameters, and adds an additional assert statement on top of what was already written:

class NewWayToRunThings_TestClass(MyTestClass):
        run_parameters = {param1: 'blue'}
        # Want someTest, and all other tests in MyTestClass to now run 
        # with an additional assert statement  

Is there someway to accomplish this so that each test runs with an additional assert statement to check that my parameter change worked properly across all my tests?

EMiller
  • 2,792
  • 4
  • 34
  • 55
  • http://stackoverflow.com/questions/5481623/python-dynamically-add-decorator-to-class-methods-by-decorating-class – dm03514 Oct 13 '16 at 19:46

1 Answers1

0

Yes there is but it may not be a good idea because:

  • assertions are hidden behind difficult to understand python magic
  • assertions aren't explicit

Could you update your methods to reflect the new contract, and expected param?

Also if a single parameter change breaks a huge amount of tests, where it is easier to dynamically patch the test class then it is to update the tests, the test suite may not be focused enough.

dm03514
  • 54,664
  • 18
  • 108
  • 145