pytest-dev / pytest-dev/pytest-bdd
can not retrieve caplog results in pytest-bdd specifications
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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