-1

I've create nose test:

import nose
from nose.tools import istest, nottest
nose.run()
path1 = "/some/my/path1/"
path2 = "/some/my/path2/"

@istest
def compare_dir(path1, path2):
    my_bool = mytest, bool
    yield my_test, my_bool 
    sub_path1 = path1 + "some_path" 
    sub_path2 = path2 + "some_path"
    compare_dir(sub_path1, sub_path2)

def my_test(is_equal):
    assert is_equal, "Not equal!"

And I've got error:

Traceback (most recent call last):
  File "/Python27/lib/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
TypeError: compare_dir() takes exactly 2 arguments (0 given)

What am I do wrong? I've already give 2 arguments for compare_dir. I've start test as

/path/to/my/test/my_test_name.py --tests=my_test_name
nick_gabpe
  • 5,113
  • 5
  • 29
  • 38

1 Answers1

1

From what i can tell it's because you're making an assumption that your function take the global variables path1 and path2 by default, which it won't, at the function initiaton level you won't get implied values unless you explicitly define them.

You could try changing

def compare_dir(path1, path2):

to

def compare_dir(path1=path1, path2=path2):

That way if nothing is passed by default it should assume the global values.

Keef Baker
  • 641
  • 4
  • 22
  • Thank you very much! `def compare_dir(path1=path1, path2=path2):` This one does work! But why it does not take value from 4 and 5 lines? – nick_gabpe Jan 19 '17 at 13:07
  • Because when you put values like that in a function you're saying that's what you want to call anything passed it within the function. So it assumes they're brand new variables to be used inside that function only. – Keef Baker Jan 19 '17 at 13:10
  • You could call it with `compare_dir(path1, path2)` in your code but all defined variables at the start of functions are by default nothing and need to be filled in. – Keef Baker Jan 19 '17 at 13:10