[Twisted-Python] Getting nice logging outputs in py.test

Amber Brown hawkowl at atleastfornow.net
Fri Jul 5 04:47:29 MDT 2019


On 5/7/19 8:27 pm, Thomas Westfeld wrote:
>>> Dear all,
>>>
>>> I am having an issue with logging of my Twisted application. I am using the new
>> twisted.logger framework. The output produced by twist or twistd when runnning my
>> plugin is nice.
>>> However when running a test suite using py.test I only get this as an output to
>> stdout:
>>
>> How are you running the reactor in your pytest suites? I've not found a
>> sane way to do this and so would recommend sticking with trial, crufty
>> and old though it feels...
> Well actually I do not. I use the subprocess module to start the server using twist and then use requests in the tests to test the HTML server and compare the results with the expected results.
>
> And yes py.test eats stdout but it is great as I need a good looking html test report which can be also customized and py.test gives me just this.
>
> Sounds like there is no easy way of configuring a nice stdout log...

Oh, that's why.

If twist detects something that isn't a terminal, it outputs JSON 
because it's not a human looking at it, which is easier for logging 
systems to consume than straight text.

You can pass `--log-format=text` as a command line argument to twist to 
override this.

- Amber




More information about the Twisted-Python mailing list