pydantic / pydantic/pytest-examples

multi-line prints in async def main are sometimes mis-indented

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

Nobody has claimed this yet.

Dominant language
Python
Stars
178
Forks
25
Avg merge
4d 1h
Merged PRs (30d)
7

Description

import asyncio
import time

from pydantic_evals import Case, Dataset

# Create a dataset with multiple test cases
dataset = Dataset(
    cases=[
        Case(
            name=f'case_{i}',
            inputs=i,
            expected_output=i * 2,
        )
        for i in range(5)
    ]
)


async def double_number(input_value: int) -> int:
    """Function that simulates work by sleeping for a second before returning double the input."""
    await asyncio.sleep(0.1)  # Simulate work
    return input_value * 2

async def main():
    # Run evaluation with unlimited concurrency
    t0 = time.time()
    report_default = await dataset.evaluate(double_number)
    print(f'Evaluation took less than 0.2s: {time.time() - t0 < 0.2}')
    #> Evaluation took less than 0.2s: True
    report_default.print()
"""
  Evaluation Summary:
     double_number
┏━━━━━━━━━━┳━━━━━━━━━━┓
┃ Case ID  ┃ Duration ┃
┡━━━━━━━━━━╇━━━━━━━━━━┩
│ case_0   │  101.0ms │
├──────────┼──────────┤
│ case_1   │  101.0ms │
├──────────┼──────────┤
│ case_2   │  101.0ms │
├──────────┼──────────┤
│ case_3   │  101.0ms │
├──────────┼──────────┤
│ case_4   │  101.0ms │
├──────────┼──────────┤
│ Averages │  101.0ms │
└──────────┴──────────┘
"""

    # Run evaluation with limited concurrency
    t0 = time.time()
    report_limited = await dataset.evaluate(double_number, max_concurrency=1)
    print(f'Evaluation took more than 0.5s: {time.time() - t0 > 0.5}')
    #> Evaluation took more than 0.5s: True
    report_limited.print()
"""
  Evaluation Summary:
     double_number
┏━━━━━━━━━━┳━━━━━━━━━━┓
┃ Case ID  ┃ Duration ┃
┡━━━━━━━━━━╇━━━━━━━━━━┩
│ case_0   │  101.0ms │
├──────────┼──────────┤
│ case_1   │  101.0ms │
├──────────┼──────────┤
│ case_2   │  101.0ms │
├──────────┼──────────┤
│ case_3   │  101.0ms │
├──────────┼──────────┤
│ case_4   │  101.0ms │
├──────────┼──────────┤
│ Averages │  101.0ms │
└──────────┴──────────┘
"""

Contributor guide

No contributing guide indexed for this repository

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 reproducing the issue with the Python example in the report, focusing on the multi-line output produced from async def main. Then trace pytest-examples' handling of captured example output and indentation. Done means the displayed multi-line prints retain the intended indentation without affecting the surrounding example.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.