pytest-bdd icon indicating copy to clipboard operation
pytest-bdd copied to clipboard

can not retrieve caplog results in pytest-bdd specifications

Open jruizaranguren opened this issue 2 years ago • 0 comments
trafficstars

pytest caplog fixture enables the capture of logs so they can be used in assertions.

It seems that py.test bdd steps are capturing out streams somehow so this information is lost. An example of test that fails:


"""we can verify logs feature tests."""

import logging
from pytest_bdd import (
    scenario,
    then,
    when,
)

@scenario('log.feature', 'Logs are retrieved')
def test_logs_are_retrieved():
    """Logs are retrieved."""


@when('user performs an auditable action', target_fixture="logs")
def _(caplog):
    """user performs an auditable action."""
    logging.info("log this")
    return caplog


@then('action is audited')
def _(logs):
    """action is audited."""
    assert logs.records

jruizaranguren avatar Jan 27 '23 11:01 jruizaranguren