It refers to the instance of that invokes the method, in this case an instance of TestCalc
. However, you never see the instances specifically, unless you write your own test runner. Otherwise, you typically only interact with the instance (aside from calling the various assert*
methods) if you override setUp
to configure the fixture.
For example,
class MyTest(unittest.TestCase):
def setUp(self):
self.x = SomeClass()
def test_foo(self):
self.assertEqual(self.x.foo(), 3)
def test_bar(self):
self.assertEqual(self.x.bar(), 6)
x
is an instance of a class that you want to use in multiple tests. Rather than call x = SomeClass()
in every test method, you call it once in setUp
and save the result as an attribute of the test case itself, making it available to each test method.