-----
def test_g():
pass
def test_f():
pass
-----
When this file is passed to nose, g() and f() are run in order as
expected. How ever, when f() is decorated as follows:
-----
import functools
def dectest(func):
def wrapper(*args, **kw):
return func()
return functools.update_wrapper(wrapper, func)
def test_g():
pass
@dectest
def test_f():
pass
-----
the oder of tests becoms f() and g(). Can some one tell me how
decorator is impacting the oder here?
On a separate note, nose docs say that the test methods in a class are
run alphabetically. Is there any way for them to be run in the same
order they are defined?
Thanks,
Raghu
> the oder of tests becoms f() and g(). Can some one tell me how
> decorator is impacting the oder here?
This is because the decorator replaces the function; nose uses the
co_firstlineno attribute of the func_code of the function to put tests
in order. When nose sees the function it doesn't see f(), but wrapper,
which is defined earlier in the file. If you want to avoid that, use
nose.tools.make_decorator.
> On a separate note, nose docs say that the test methods in a class are
> run alphabetically. Is there any way for them to be run in the same
> order they are defined?
Not automatically, no. They don't have func_code.co_firstlineno
attributes to use for sorting. So if you want them to come out in the
same order you have them in the file, you have to name them
alphabetically (test_01_real_name, test_02_another_test, etc).
JP
Thanks. Using nose.tools.make_decorator does the trick.
IPython can find method source, so I dug into this a bit.
method.im_func.func_code.co_firstlineno seems to work.
-Ken