pytest-dev / pytest-dev/pytest-bdd

can not retrieve caplog results in pytest-bdd specifications

Open
#597 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
251
Avg merge
43m
Merged PRs (30d)
2

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the inline pytest-bdd example with the caplog fixture and checking whether logging.info("log this") appears in logs.records. Trace how the @when step with target_fixture="logs" passes caplog into the @then step. Done means the assertion succeeds and captured records remain available to the step definition.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.