Python: Where to put a one time initialization in a test case of unittest framework?
<p>My test is simple. I want to send two requests to two different servers then compare whether the results match.</p>

<p>I want to test the following things.</p>

<ol>
<li>send each request and see whether the return code is valid.</li>
<li>compare different portion of the outputs in each test method</li>
</ol>

<p>I do not want to send the requests in setUp method because it will be send over and over for each new test. I would rather want to send the requests at the initialization. (maybe in the <strong>init</strong> method). But I found a lot of people were against that idea because they believe I should not override the init method for some reason. (I do not know exactly why) If that's the case, where should I send the requests?
I am kind of against doing them in the class body (as shared variables).</p>

<p>A class method called before tests in an individual class run. setUpClass is called with the class as the only argument and must be decorated as a classmethod():</p>

<pre><code>@classmethod
def setUpClass(cls):
    ...
</code></pre>

<p>See: <a href="https://docs.python.org/3/library/unittest.html#unittest.TestCase.setUpClass" rel="nofollow">https://docs.python.org/3/library/unittest.html#unittest.TestCase.setUpClass</a></p>

python python-2.7 unit-testing python-unittest