Search code examples
pythonunit-testingpython-decoratorsnosenumba

Python: How to ignore decorators during unit (nose) tests?


I want to ignore certain decorators on my code to have the associated functionality skipped, but only when running as a part of a unit test. Can this be done?

For example I have a function f, defined with a numba decorator like so:

@numba.jit
def f(a, b):
  return a + b

When I run a unit test that calls the above function I don't want the numba magic to happen, as it can slow things down and cause errors on some platforms. Is it possible to make a setting someplace that tells nose to run tests without any numba just-in-time (and/or all numba) decorators being applied?


Solution

  • For numba only, you can set an environment variable (eg. export NUMBA_DISABLE_JIT=1) to make the jit decorators no-ops.

    http://numba.pydata.org/numba-doc/dev/user/troubleshoot.html#disabling-jit-compilation