Skip to content

Add compatibility helper for older Pytest versions#47

Draft
cottsay wants to merge 1 commit intomainfrom
cottsay/old-pytest
Draft

Add compatibility helper for older Pytest versions#47
cottsay wants to merge 1 commit intomainfrom
cottsay/old-pytest

Conversation

@cottsay
Copy link
Copy Markdown
Member

@cottsay cottsay commented Apr 10, 2026

The tmp_path fixture was introduced in Pytest 3.9. Include an explicit definition of that fixture for compatibility with those older Pytest versions. When we're ready to drop support, we can just remove the fixture.

We could test this in GitHub Actions but it would be pretty contrived. I think it would be OK to carry this as a compatibility extension without explicitly testing it in CI, but I'm open to hearing differing opinions.

The `tmp_path` fixture was introduced in Pytest 3.9. Include an explicit
definition of that fixture for compatibility with those older Pytest
versions. When we're ready to drop support, we can just remove the
fixture.
@cottsay cottsay self-assigned this Apr 10, 2026
@cottsay cottsay added the enhancement New feature or request label Apr 10, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.82%. Comparing base (78cb048) to head (c0586cd).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #47   +/-   ##
=======================================
  Coverage   51.82%   51.82%           
=======================================
  Files          20       20           
  Lines        2678     2678           
  Branches      546      546           
=======================================
  Hits         1388     1388           
  Misses        971      971           
  Partials      319      319           

☔ View full report in Codecov by Sentry.
📢 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.

Comment thread test/conftest.py
import pytest


if getattr(pytest, 'version_tuple', ()) < (3, 9):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Seems like pytest.version_tuple is not exported in pytest 3.9–6.x, so getattr(pytest, "version_tuple", ()) < (3, 9) still evaluates true. This triggers an unfortunate chain of problems:

  1. On pytest 3.9.3 and 6.2.5, pytest.version_tuple is not exported.
  2. getattr(..., ()) returns ().
  3. In Python, () < (3, 9) is True.
  4. The compatibility fixture is defined even though pytest already provides tmp_path.

Checked locally with uv:

/tmp ❯ uv pip install "pytest<7.0"
Resolved 7 packages in 80ms
Prepared 4 packages in 84ms
Installed 4 packages in 4ms
 + attrs==26.1.0
 + py==1.11.0
 + pytest==6.2.5
 + toml==0.10.2
/tmp ❯ python3
Python 3.10.20 (main, Mar 20 2026, 00:33:12) [Clang 22.1.1 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytest
>>> getattr(pytest, 'version_tuple', ()) < (3, 9)
True
>>> getattr(pytest, 'version_tuple', ()) 
()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

😞 that's a bummer. I'll have a closer look. Thanks!

@cottsay cottsay marked this pull request as draft April 13, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants