Reputation: 9
I'm trying to test an add function that excites in calc.py
import unittest
import calc
class TestCalc(unittest.TestCase):
def test_add(self):
result = calc.add(10,5)
self.assertEqual(result,15)
My question is what does self means in this example
I know that self is an instance of a class.But, can you give me an example of what the value of self would be in my example.
Upvotes: 0
Views: 610
Reputation: 434
self
is a reference to the instance of TestCalc
that is instantiated by the test runner from unittest when you run your tests.
More generally, when an object is instantiated and one of its methods is called (such as test_add()
, called by unittest's test runner in your case), self
is used to refer to the instance the method is called on, allowing access to its other properties and methods (such as assertEqual()
, inherited from unittest.TestCase
, in your case).
Upvotes: 1