[merge][#124153][#124849] clean up capturing logging from within tests

John Arbash Meinel john at arbash-meinel.com
Tue Jan 22 18:51:05 GMT 2008


Martin Pool wrote:
>  * remove some crufty globals from bzrlib.trace
>  * enable_test_log and disable_test_log are now properly symmetric and
> restore the previous state
>  * ... except that they're deprecated for new names push_test_log and
> pop_test_log
>  * and this is one major step towards being able to test bzrlib from
> under a normal TestRunner, and generally makes it cleaner as a library
> 
> With this, we still have debug messages going out direct to a file,
> and everything else through logging.py.  Logging.py is a bit slow, but
> now that most of our debug statments are guarded by a check of
> debug_flags this may not be a big deal.  So later on, someone could
> make them all go through logging.py, and there is scope for some more
> cleanups.
> 
> 

BB:tweak

The concept seems good, and I didn't see anything bad in the code. But I 
didn't see any tests that the push and pop work properly either. I think 
it would be good to add a test that:

trace.mutter('foo')
token1 = trace.push_log_file('my-test-file.log')
trace.mutter('bar')
token2 = trace.push_log_file('another-test-file.log')
trace.mutter('baz')
trace.pop_log_file(token2)
trace.mutter('fizzle')
trace.pop_log_file(token1)
trace.mutter('frazzle')

self.check_file_contents('my-test-file.log', 'bar\nfizzle\n')
self.check_file_contents('another-test-file.log', 'baz\n')

We would need to be careful, because you open the file in "at" so we 
need to translate the line endings on Windows.

John
=:->



More information about the bazaar mailing list