Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <hr> <p>UPDATE:</p> <p>Since you need to: </p> <ol> <li>feed some variable value to MyTestCase</li> <li>run MyTestCase using this value</li> <li>change value</li> <li>If MyTestCase still running - use updated value.</li> </ol> <p>Consider this:</p> <ol> <li>keep values map in the file (.csv/.txt/.xml/etc.)</li> <li>read values map from file in the <code>setUp()</code></li> <li>find value for your MyTestCase from values map using <code>TestCase.id()</code> method (as shown in the example below).</li> <li>use it in the test cases.</li> </ol> <hr> <p><code>unittest</code> has handy <code>id()</code> <a href="http://docs.python.org/library/unittest.html#unittest.TestCase.id" rel="nofollow">method</a>, which returns test case name in <code>filename.testclassname.methodname</code> format.</p> <p>So you can use it like this:</p> <pre><code>import unittest my_variables_map = { 'test_01': 'foo', 'test_02': 'bar', } class MyTest(unittest.TestCase): def setUp(self): test_method_name = self.id() # filename.testclassname.methodname test_method_name = test_method_name.split('.')[-1] # method name self.variable_value = my_variables_map.get(test_method_name) self.error_message = 'No values found for "%s" method.' % test_method_name def test_01(self): self.assertTrue(self.variable_value is not None, self.error_message) def test_02(self): self.assertTrue(self.variable_value is not None, self.error_message) def test_03(self): self.assertTrue(self.variable_value is not None, self.error_message) if __name__ == '__main__': unittest.main() </code></pre> <p>This gives you: </p> <pre><code>$ python /tmp/ut.py ..F ====================================================================== FAIL: test_03 (__main__.MyTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/tmp/ut.py", line 25, in test_03 self.assertTrue(self.variable_value is not None, self.error_message) AssertionError: No values found for "test_03" method. ---------------------------------------------------------------------- Ran 3 tests in 0.000s FAILED (failures=1) $ </code></pre>
    singulars
    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