Testing class methods with pytest
<p>In the documentation of pytest various examples for test cases are listed. Most of them show the test of functions. But Iâm missing an example of how to test classes and class methods. Letâs say we have the following class in the module <code>cool.py</code> we like to test:</p>

<pre><code>class SuperCool(object):

    def action(self, x):
        return x * x
</code></pre>

<p>How does the according test class in <code>tests/test_cool.py</code> have to look?</p>

<pre><code>class TestSuperCool():

    def test_action(self, x):
        pass
</code></pre>

<p>How can <code>test_action()</code> be used to test <code>action()</code>?</p>

<p>All you need to do to test a class method is instantiate that class, and call the method on that instance:</p>

<pre><code>def test_action(self):
    sc = SuperCool()
    assert sc.action(1) == 1
</code></pre>

python py.test