[GRASS-dev] Add a possible decorators to gunittest

Pietro peter.zamb at gmail.com
Tue Mar 29 03:49:22 PDT 2016


Dear Vaclav,

I wrote a first draft of a decorator: change_environ [0], that:
1. overwrite the environment variables,
2. execute the test and
3. restore the environment variables.

Probably I should modify the function with something like:

{{{
           try:
               func(*args, **kwargs)
           finally:
               # restore the environment variables
               for k, v in envs.items():
                   oval = original_envs[k]
                   if oval == NOT_FOUND:
                       os.environ.pop(k)
                   else:
                       os.environ[k] = oval
}}}

Otherwise if the function raise an exception the current
implementation will not restore the environment variables back to
their original value.

But I think this kind of functionalities is general enough to be
somewhere in the gunittest code.

What do you think? Any idea?

All the best.

Pietro

[0] https://trac.osgeo.org/grass/browser/grass/trunk/lib/python/script/testsuite/test_utils.py#L10


More information about the grass-dev mailing list