Friday, October 24, 2008

nosetests part 2 - the final solution

Ok, some more freetime for me today! Yay!
Now I have actually time to investigate some more about the nosetests - python vs CruiseControl log output feature.
Let's see, where did we leave? Hm, by trying to get some proper xml formatted output for the Cruisecontrol, we discovered that if Syslog plugin was used as well, the output would not had been formed (for some strange reasons). The problem arises from the fact that we use syslog to "log" internal test activity (for an example, when a test starts and ends, to log exceptions etc).

Main reasons for that include :

  • xml logging targeted messages redirected to syslog
  • syslog interfers and breaks xml logging
Let's check the first one.

Xml formatted output should be produced if the switch "--with-nosexunit" is present on the command line.
So let's perform the two test cases in here:

nosetests --with-nosexunit --xml-report-folder=c:\temp,

which produces a TEST-test_mytest.xml file in c:\temp and

nosetests --sysloghost=localhost --with-nosexunit --xml-report-folder=c:\temp

which doesnt.

Now we have two effects in here, which push the problem into a somekind of "limbo" (no, not mambo): on one hand, we know for sure that the xml formatted output is not produced by nosexunit - The nosexunit library simply captures the stdio / stderr from the script it's running and outputs it accordingly to the commandline arguments it has obtained, so this means (probably) that no input is fed to the nosexunit (which is why, in turn, the output is not produced); we also know that the expected xml-formatted output created by nosexunit is not present in our syslog target. This excludes the (least likely) case in which the output is produced by nosexunit and gets (for some strange and impossible reason) to the syslog host.

This means that it gets lost somewhere in between. In between where? Well, nosexunit is a plugin as well. Could it be that the output to be formatted gets lost between the two plugins? To be able to answer this question, a few more tests need to be executed.

The syslog plugin which we use internally is home-made (obviously) and worked fine up to a few weeks ago. Well, it worked fine means "it never showed any problems". What does the plugin do - it adds a new listener to the logging instance, by doing the following :
self.logger = logging.getLogger("nosetest")

sysLogHandler = logging.handlers.SysLogHandler((options.sysloghost, 514))
formatter = logging.Formatter("%(name)-30s: %(message)s")

Obviously this piece of code interferes somehow with the nosexunit library.

No comments: