Hello gang,
while I was playing around with ResultsDB, I've come to some issues,
which bothered me to the level I wrote a fix :)
1) Common base class for the tests
-----------------------------------
[patch 0001 - lib/python/test.py]
While rewriting the tests, so they store the results in resultsdb, i
found myself doing repetitive work - i needed to write the same code to
__all__ the test files, which is a boring job, which i do not want to do
ever again :)
Fortunately this can be solved by creating a common parent class (lets
call it BaseTest) for all the tests. This class will then implement all
the repetitive code (e.g. sending the email, loading config...), and
only local "specialities" need to be handled in the test.
The main thought behind the BaseTest is that if we setup few common
variables (result, summary, highlights, outputs) as instance variables,
we can then use the postprocess function (which is called after the
run_once successfully [and note the 'successfully' for later] ends).
[note]
This is also a pre-step to switching to ResultsDB as all the changes
required to add basic resultsdb storage is about 7 lines in the BaseTest.
[/note]
[patch 0002]
For the email's sake in current 'send email to results list' model, the
postprocess fuction implements the email-sending. Summary is the subject
and highlights + outputs are body. The self.mail_to list is filled in
the tests which have the "inform package owners" fuctionality.
2) ExceptionCatcher decorator
-----------------------------
[patch 0001 - lib/python/decorators.py]
What the heck is this?!? Well, you remember, that the 'postprocess'
function is called only if the run_once ends well (i.e. no exception is
thrown from the run_once). This, of course, is absolutely not OK, if one
wants to have some common "out" point - e.g. call the postprocess function.
This decorator then watches over the decorated function, and if
exception is raised, the decorator stores it, calls the
'exception_happened' function (which is given as parameter to the
decorator, see the docstring for more detail), and then re-raises the
exception.
This practically gives us the opportunity to call the postprocess
method. In fact, I call "FOOBAR_failed" method, which potentially sets
the result & summary (if not already set) and then calls the postprocess.
Using the decorator has also a small drawback - **kwargs needs to be set
as last parameter of the decorated function. This is because autotest
does some nasty magic with introspection to find out which parameters
the function (initialize, run_once) has and it fails on the decorated
function, so it just blindly uses all the parameters specified in the
control file.
3) Tests & templates rewritten
------------------------------
[both patches]
I also rewrote the tests & templates so they implement this
functionality, I did not have time to test it yet, so it's probable,
that there are some typing errors and stuff, but i think it's important
to show you, how will the new style of test writing work, once this
patch is pushed.
Please comment, ask questions, share ideas - I believe that this is an
important issue and would like all of you to be happy about it.
joza