Capturing binary output using pytest capsysmodule doesn't work

Summary

Capturing binary output using pytest capsys module is causing a "Bad file descriptor" OS error.

This is preventing the https://gitlab.com/BuildStream/buildstream/blob/master/tests/frontend/buildcheckout.py#L121 test from being activated.

Steps to reproduce

Remove the line https://gitlab.com/BuildStream/buildstream/blob/master/tests/frontend/buildcheckout.py#L121 and run the tests.

What is the current bug behavior?

The capsys module aborts with an "Bad file descriptor" error.

What is the expected correct behavior?

The output binary data to be successfully captured.

Relevant logs and/or screenshots

==================================================================================================== FAILURES =====================================================================================================
_______________________________________________________________________________________ test_build_checkout_tarball_stdout ________________________________________________________________________________________

datafiles = local('/home/tiagogomes/repos/buildstream/tmp/test_build_checkout_tarball_st0'), cli = <tests.testutils.runcli.Cli object at 0x7f9736fb2780>

    @pytest.mark.datafiles(DATA_DIR)
    def test_build_checkout_tarball_stdout(datafiles, cli):
        project = os.path.join(datafiles.dirname, datafiles.basename)
        tarball = os.path.join(cli.directory, 'tarball.tar')
    
        result = cli.run(project=project, args=['build', 'target.bst'])
        result.assert_success()
    
        builddir = os.path.join(cli.directory, 'build')
        assert os.path.isdir(builddir)
        assert not os.listdir(builddir)
    
        checkout_args = ['checkout', '--tar', 'target.bst', '-']
    
>       result = cli.run(project=project, args=checkout_args)

tests/frontend/buildcheckout.py:136: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/testutils/runcli.py:265: in run
    result = self.invoke(bst_cli, bst_args)
tests/testutils/runcli.py:318: in invoke
    out, err = capture.readouterr()
.eggs/pytest-3.6.3-py3.6.egg/_pytest/capture.py:437: in readouterr
    self.out.snap() if self.out is not None else "",
.eggs/pytest-3.6.3-py3.6.egg/_pytest/capture.py:526: in snap
    res = FDCaptureBinary.snap(self)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <FDCapture 1 oldfd=11>

    def snap(self):
>       self.tmpfile.seek(0)
E       OSError: [Errno 9] Bad file descriptor

.eggs/pytest-3.6.3-py3.6.egg/_pytest/capture.py:489: OSError

Other relevant information

  • BuildStream version affected: /milestone %BuildStream_v1.x