vendredi 24 mars 2017

An explicitly enabled capsys pytest fixture

The pytest capsys fixture is really useful, but it captures everything immediately whenever it is included as a fixture. I only want to capture output from a particular line in the test.

It does actually provide a "disabled" context:

def test_disabling_capturing(capsys):
    print('this output is captured')
    with capsys.disabled():
        print('output not captured, going directly to sys.stdout')
    print('this output is also captured')

But I want something like the opposite of that:

def test_disabling_capturing(capsys):
    print('this output is not captured')
    with capsys.enabled():
        print('output is captured')
    print('this output is also not captured')

Is it possible with capsys fixture somehow?

Aucun commentaire:

Enregistrer un commentaire