title: Using self vs cls to access variable in unittest
body: <p>Lets say I have a simple class object that looks like some sort of <code>Counter</code> (of course it has other functions but it's out of scope for this question):</p>
  
  <pre><code>from collections import Counter
  
  class Vocabulary:
      def __init__(self, words):
          self.vocab = Counter(words)
  </code></pre>
  
  <p>And adding the <code>Vocabulary</code> class to a unittest, I could have use the <code>setUpClass</code> classmethod as such:</p>
  
  <pre><code>import unittest
  
  class VocabularyTests(unittest.TestCase):
      @classmethod
      def setUpClass(cls):
          cls.vocab = Vocabulary(["z", "a", "b", "c", "f", "d", "e", "g", "a", "d", "b", "e", "w"])
  
  
      def test_counts_set_correctly(self):
          self.assertEqual(cls.vocab["a"], 2)
  </code></pre>
  
  <p>Or I could have just use <code>self</code>:</p>
  
  <pre><code>class VocabularyTests(unittest.TestCase):
      def __init__(self, *args, **kwargs):
          super(VocabularyTests, self).__init__(*args, **kwargs)
          self.vocab = Vocabulary(["z", "a", "b", "c", "f", "d", "e", "g", "a", "d", "b", "e", "w"])
  
      def test_counts_set_correctly(self):
          self.assertEqual(self.vocab["a"], 2)
  </code></pre>
  
  <p>And both of the above would work fine. But what if I've a sort of unpythonic pattern:</p>
  
  <pre><code>import unittest
  
  class VocabularyTests(unittest.TestCase):
      @classmethod
      def setUpClass(self):
          self.vocab = Vocabulary(["z", "a", "b", "c", "f", "d", "e", "g", "a", "d", "b", "e", "w"])
  
  
      def test_counts_set_correctly(self):
          self.assertEqual(self.vocab["a"], 2)
  </code></pre>
  
  <p>According to <a href="https://stackoverflow.com/questions/4613000/what-is-the-cls-variable-used-for-in-python-classes">What is the &#39;cls&#39; variable used for in Python classes?</a>, it's just a coding convention but is there any difference between the 3rd version of the unittest with <code>@classmethod</code> with the usage of <code>self.vocab</code> and the first two more idiomatic tests?</p>