Skip to content

Update call to match pytest-benchmark >= 5.3.0 - #20

Merged
olivialynn merged 2 commits into
mainfrom
fix-benchmark-json-path
Oct 14, 2026
Merged

olivialynn merged 2 commits into
mainfrom
fix-benchmark-json-path

Conversation

@olivialynn

@olivialynn olivialynn commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Avoids empty pytest-benchmark.json when running with --lbench, with newer versions of pytest-benchmark.

I went in with my human eyes and tracked down the change to an upstream commit made just before pytest-benchmark v5.3.0: ionelmc/pytest-benchmark@cb91999

What had broken:
Running pytest --lbench didn't save benchmark results.

At the end of the session, pytest-benchmark would raise TypeError: expected str, bytes or os.PathLike object, not BufferedWriter, and leave behind the already-created 0 byte <run_dir>/pytest-benchmark.json.

Why:
We were setting config.option.benchmark_json to an open file handle, which was totally right at the time.

But now, pytest-benchmark >= 5.3.0 declares it with type=Path and opens the file itself when trying to save results - so, the already-open file object fails, and the file created at startup stays empty.

Fix:

  • Set benchmark_json to a path and let pytest-benchmark open it
  • Require pytest-benchmark>=5.3.0, since this relies on its path-based option

pytest-benchmark >= 5 declares --benchmark-json with type=Path and
calls open(path, "wb") itself when saving results. The --lbench setup
passed an already-open file object, so saving raised a TypeError and
pytest-benchmark.json was left empty (0 bytes).

Set benchmark_json to the path instead and require pytest-benchmark>=5,
whose option handling this relies on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 3.48%. Comparing base (a214c4a) to head (b781031).

Files with missing lines Patch % Lines
src/lbench/pytest/plugin.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main     #20   +/-   ##
=====================================
  Coverage   3.48%   3.48%           
=====================================
  Files         26      26           
  Lines       1062    1062           
=====================================
  Hits          37      37           
  Misses      1025    1025           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@smcguire-cmu smcguire-cmu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! I hated this at the time, it's nice to see it updated

@olivialynn
olivialynn merged commit b1b2e72 into main Oct 14, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants