title: LPTHW:Ex48 Unit test(using nosetests), Classes,method arguments TypeErrors
body: <p>I am Newbie working through LPTHW <a href="http://learnpythonthehardway.org/book/ex48.html" rel="nofollow noreferrer">This is the link for it</a>. At ex48 I am given a lot of code as unit tests to which I am supposed to write the corresponding my_code which will be tested(using nosetests, sorry lots of tests in this sentence.)</p>
  <p>this is my_code:</p>
  <pre><code>class lexicon(object):
  
      def __init__(self):
      #some initial stuff.
  
      def scan(self,stuff):
      #some cool code.
  </code></pre>
  <p>And this is the test.py file</p>
  <pre><code>from nose.tools import*
  from Ex48.code import lexicon
  
  def test_directions():    
  
      assert_equal(lexicon.scan(&quot;north&quot;), [('direction', 'north')])
      ...#Unimportant details the above is enough.
  </code></pre>
  <p>However when I run nosetests I get the following error:</p>
  <pre><code>Traceback (most recent call last):
      File &quot;c:\python31\lib\site-packages\nose'case.py&quot;, line 197, i runTest
      ... line x, in test_directions
      assert_equal(lexicon.scan(&quot;north&quot;), [('direction', 'north')])
  TypeError: scan() takes exactly 2 positional arguments (1 given)
  </code></pre>
  <p>Which is odd because one of those 2 arguments is the self one and I thought it should not be given.</p>
  <p>To remedy this problem I have tried:</p>
  <pre><code>@staticmethod
  def scan(self,stuff):
  </code></pre>
  <p>But this gave me the same typeError</p>
  <p>Next I tried:</p>
  <pre><code>assert_equal(lexicon.__init__(self).scan(...)
  </code></pre>
  <p>But this didn't work either(I think .<strong><strong>init</strong></strong>(self) should be used in another class than lexicon only, not in main).</p>
  <p>I Finally resolved to:</p>
  <pre><code>lexicon1=lexicon()
  def test_directions():    
      assert_equal(lexicon1.scan(&quot;north&quot;), [('direction', 'north')])
  </code></pre>
  <p>But this is not how the exercise is supposed to be done!</p>
  <p>P.S: I did not include the whole traceback because it might not be necessary(and it's getting very late). I did not include parts of my code bc I'm sure that it works fine and is not causing the error!</p>