unit testing - How can one use the logging module in python with the unittest module? -


I would like to use Ajith logging module to log in with all output so that I include it in the test I'm trying to write the structure. Its goal is to run the test with 2 sets of output, with a simple output, which tells the test case phase and more debug level output so that when things go wrong We know as much as possible Ho. Production will be placed in two files, one is that I can email people, and in case of other failures. I saw that TextTestRunner could use a stream, can it be used with logging modules? I am planning to use some new features in Dragon 2.7.

You can, but I can '

  1. Instant an in-memory stream that can be used by TextTestRunner . Like this thing, io.StringIO will be almost complete, except that it only works with Unicode input, and I'm not sure TextTestron writes UNICODE properly in the stream.

  2. Create your own. Make your own investment initialize with TextTestRunner and this in-memory stream.

  3. Create a class that reads from the stream and writes it in the log.

It can be as simple as:

  class stream logger (object): def __init __ (self, input_stream, output_logger) : Self.input_stream = input_stream self.output_logger def run (self): while true: line = input_stream.readline () if not line: break output_logger. Terror (line)  

Problems with this approach:

  • You do not have any flexibility in directing different parts of TextTestRunner to different log levels.
  • TextTestRunner, if incorrectly configured, will write a bunch of stuff that you probably do not want is the default verb 1, which you will write progress points while testing ... which may be logging Output will come in your way.
  • If you do this stuffy, you will call stream_logger.run () after you just type all your output into the stream, in this way, Logging will not receive output, and your logging timestamp will be unusable. For example, by creating a separate pouch to read, you can solve it, but then you need to select / roll the stream that the reader and author can work with Thread together, or a process thorn And may eat in-store streams, or some are relatively complex.

I want to suggest instead that to drop the currents and just roll your own test runner - say, Loggingstustner - the way that the test outputs are written in the logger From that you want it to output it will allow you to avoid these three problems.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -