[pytest-dev] Is it valid to use --boxed with --capture=no?

holger krekel holger at merlinux.eu
Thu Sep 25 14:59:37 CEST 2014


Hi David,

On Thu, Sep 25, 2014 at 11:39 +0100, David Röthlisberger wrote:
> Hi Holger, thanks for your quick response.
> 
> > > Is it valid to use --boxed with --capture=no? It fails with
> > > UnicodeEncodeError. More details at
> > > https://bitbucket.org/hpk42/pytest/issue/573
> >
> > In any case, could you please update the issue using the latest 
> > pytest-2.6.3 and pytest-xdist-1.11?
> 
> Done. The issue remains the same.
>
> > Do you need to timestamp the captured output as one big thing or per line?
> 
> I add a timestamp to each line, similar to the "ts" utility from
> moreutils[1] but in-process in python.
> 
> I do this by "dup2"ing stdout & stderr to a a named pipe. There's a
> thread reading from the pipe, timestamping each line and writing it to
> a logfile.
> 
> [1] http://manpages.ubuntu.com/manpages/trusty/man1/ts.1.html
> 
> 
> > Could you give a somewhat real-life example of what you would like to
> > customize in a pytest run?
> 
> This may be more detail than you care about, but here goes:
> 
> Stb-tester tests set-top boxes by capturing video from the set-top box
> (using video-capture hardware) and sending infrared signals to the
> set-top box (using a usb infrared emitter). The user's tests are written
> in python.
> 
> With pytest I have a function-scope fixture that passes in an object
> that the user's test can use to access the video-processing and
> infrared-control functions.
> 
> For each test run I also make a video recording of the set-top box's
> output. The timestamps in the log allow the user to correlate the logs
> to particular points in the video.
> 
> The user can also capture other logs during a test run (for example logs
> from processes running on the set-top box itself) so the timestamps are
> also necessary to correlate these logs with stb-tester's logs of what
> the test script is doing.
> 
> I'd like to be able to capture (and timestamp) any stdout & stderr
> output written by the user's script. If this turns out to be too hard I
> could provide the user's script a function like "stb_tester.log(...)"
> which does the timestamping and writes to a file, but that would be an
> incompatible break for my users -- their scripts currently use "print"
> for logging, and unless they change their scripts that logging would be
> lost when they upgrade stb-tester to the new version that uses pytest.

Thanks for the good explanation.  If designed anew i'd indeed suggest
to use a "log" fixture like this:

    def test_some_video(log):
        log("hello")

If it's really "print" that is used and shall be used in the future, you
might also overwrite sys.stdout with an object that does the
timestamping.  Capturing at file descriptor level is only neccessary
if you have C code writing to FD1 or start subprocesses which write out.

> I need to use "--boxed" to run each test in a different process, because
> very occasionally I get segfaults from the video-capture and
> image-processing libraries that I use, and I don't want that to bring
> down the rest of the tests.

With pytest-xdist-1.11 you can also run things with "py.test -n1" now which is
faster and will restart a crashed process if neccessary.  I expect "--boxed"
to be removed if "py.test -n1" proves to be a sufficient.

best,
holger


More information about the Pytest-dev mailing list