[GRASS-dev] Add a possible decorators to gunittest

Vaclav Petras wenzeslaus at gmail.com
Tue Mar 29 06:02:27 PDT 2016

On Tue, Mar 29, 2016 at 6:49 AM, Pietro <peter.zamb at gmail.com> wrote:
> 1. overwrite the environment variables,
> 2. execute the test and
> 3. restore the environment variables.

In case the test involves just calling subprocesses, the best way probably
is to change their environment instead of changing the global one. This is
not applicable to function calls of course.

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

Although I can see advantages of decorators, Python unittest package uses
setUp() and tearDown() functions for that purpose. Introducing another
mechanism might interfere with the execution of the tests. If nothing else,
you would need to re-raise the exception to signal that the test failed. I
suggest to try setUp() and tearDown() as unittest advocates and only when
it won't work look at decorators (which are used in unittest but it
different way).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20160329/7dcd5e04/attachment.html>

More information about the grass-dev mailing list