Question

I try to use ctx.msg_start() and ctx.msg_end() as used in check_cfg to show test results of unit/func tests. But with the code below I get always additional "-----" printings and the actual text gets printed twice (the second pass is colored green in the original).

----------------------------------------Running testRunning test : PASSEDPASSED

class voodoo(Task.Task):
    run(self):
        self.generator.bld.start_msg("Running test")

        proc = Utils.subprocess.Popen(self.gt_exec,\
                                      cwd=cwd,\
                                      env=fu,\
                                      stderr=Utils.subprocess.PIPE,\
                                      stdout=Utils.subprocess.PIPE)

        (out, err) = proc.communicate()

        if proc.returncode==0:
            self.generator.bld.end_msg ("PASSED\n", 'GREEN');
        else:   
            self.generator.bld.end_msg ("FAIL", 'YELLOW');

The source shows that the output is somewhat expected but why/how does it work in check_cfg? How can I override the .to_log() method of the build context?

Was it helpful?

Solution

In fact the start_msg and end_msg were tailored for configuration. If you use them in the build you get the stdout version and the part that go to the config.log file.

One way is to set a logger :

bld = self.generator.bld

bld.logger = Logs.make_logger(path_to_some_log_file, 'mylogger')

bld.start_msg("Running test")
# do something
bld.end_msg("Test ok")

bld.logger = None

Instead of WAF Logs.make_logger, you can use a standard python logger with a NullHandler.

OTHER TIPS

Quick fix - not sure if this is madness...

    #overwrite the default logger to prevent duplicate logging
    def to_log_overwrite(x):
        pass

    self.generator.bld.to_log = to_log_overwrite

before .start_msg(...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top