Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change docstring of TestCase Class in Python?
    primarykey
    data
    text
    <p>In Python 2.5 (Jython actually), for the UnitTest TestCase Class - there's is no SetUpClass method, and <code>__init__</code> is not really acceptable (no refference to self). When I try to change docstring inside the TestCase:</p> <pre><code>import os fileName = os.path.split(__file__)[1] testCaseName = os.path.splitext(fileName)[0] setattr(__name__, '__doc__', testCaseName) </code></pre> <p>I'm getting:</p> <pre><code>setattr(__name__, '__doc__', testCaseName) TypeError: readonly attribute </code></pre> <p>I tried to change the docstring by instantiate it into an object (where <code>self.__doc__</code> is writable). </p> <blockquote> <p><strong>UPDATED:</strong> but I want to avoid additional coding in the sub-class (i.e. inheriting super-class function to set docstring of sub-class), for example:</p> </blockquote> <p><strong>File DynamicTestCase.py includes:</strong></p> <pre><code>class DynamicTestCase(unittest.TestCase): def setDocstring(self, testCaseDocstring=None): if not testCaseDocstring: fileName = os.path.split(__file__)[1] testCaseDocstring = os.path.splitext(fileName)[0] setattr(self, '__doc__', testCaseDocstring) </code></pre> <p><strong>File MyTestCase.py includes:</strong></p> <pre><code>class MyTestCase(DynamicTestCase): def test_print_docstring(self): self.setDocstring() print 'MyTestCase Docstring = ', self.__doc__ </code></pre> <p>But still, the unittest run result is:</p> <pre><code>MyTestCase Docstring = DynamicTestCase </code></pre> <p>When I expected <em>MyTestCase Docstring = MyTestCase</em> </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload