Skip to content

caching default algo fixture#414

Merged
ericbuckley merged 4 commits into
mainfrom
fix/caching-default-algo-fixture
Jun 3, 2025
Merged

caching default algo fixture#414
ericbuckley merged 4 commits into
mainfrom
fix/caching-default-algo-fixture

Conversation

@ericbuckley

@ericbuckley ericbuckley commented Jun 2, 2025

Copy link
Copy Markdown
Collaborator

Description

Replacing lru_cache decorator on default_algorithm fixture with a scope=session for reuse. Updating a handful of tests in test_link.py to modify a copy of the default_algorithm object, rather than the original, so we don't break subsequent tests using that same fixture.

Additional Notes

The latest release of pytest, 8.4.0, made changes to how fixtures are recognized and loaded. Using an lru_cache decorator on top of a pytest.fixture, is now causing the harness to not see it.

<--------------------- REMOVE THE LINES BELOW BEFORE MERGING --------------------->

Checklist

Please review and complete the following checklist before submitting your pull request:

  • I have ensured that the pull request is of a manageable size, allowing it to be reviewed within a single session.
  • I have reviewed my changes to ensure they are clear, concise, and well-documented.
  • I have updated the documentation, if applicable.
  • I have added or updated test cases to cover my changes, if applicable.
  • I have minimized the number of reviewers to include only those essential for the review.

Checklist for Reviewers

Please review and complete the following checklist during the review process:

  • The code follows best practices and conventions.
  • The changes implement the desired functionality or fix the reported issue.
  • The tests cover the new changes and pass successfully.
  • Any potential edge cases or error scenarios have been considered.

@ericbuckley ericbuckley self-assigned this Jun 2, 2025
@ericbuckley ericbuckley added the bug Something isn't working label Jun 2, 2025
@codecov

codecov Bot commented Jun 2, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.51%. Comparing base (b2deb48) to head (cca82e0).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #414   +/-   ##
=======================================
  Coverage   98.51%   98.51%           
=======================================
  Files          33       33           
  Lines        1948     1948           
=======================================
  Hits         1919     1919           
  Misses         29       29           

☔ 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.

@ericbuckley ericbuckley marked this pull request as ready for review June 2, 2025 23:08

@m-goggins m-goggins 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.

I like copying so that we aren't modifying the algorithm. One thing to note if we run into an issue like this again, it seems that switching the order of the caching and pytest.fixture also solves the problem. In 8.4.0, it seems that the pytest.fixture decorator needs to be first in order to be recognized if there are multiple decorators.

@ericbuckley

Copy link
Copy Markdown
Collaborator Author

I like copying so that we aren't modifying the algorithm. One thing to note if we run into an issue like this again, it seems that switching the order of the caching and pytest.fixture also solves the problem. In 8.4.0, it seems that the pytest.fixture decorator needs to be first in order to be recognized if there are multiple decorators.

When I just switch the order of the decorator, I get these 4 errors.

================================================================ short test summary info =================================================================
FAILED tests/unit/routes/test_link_router.py::TestMatch::test_no_match - pydantic_core._pydantic_core.ValidationError: 4 validation errors for Algorithm
FAILED tests/unit/routes/test_link_router.py::TestMatch::test_match - pydantic_core._pydantic_core.ValidationError: 4 validation errors for Algorithm
FAILED tests/unit/routes/test_link_router.py::TestMatchFHIR::test_no_match - pydantic_core._pydantic_core.ValidationError: 4 validation errors for Algorithm
FAILED tests/unit/routes/test_link_router.py::TestMatchFHIR::test_match - pydantic_core._pydantic_core.ValidationError: 4 validation errors for Algorithm
================================================= 4 failed, 275 passed, 1 skipped, 20 warnings in 2.40s ==================================================

@m-goggins

Copy link
Copy Markdown
Collaborator

Oh, I see. On my branch I just switched the order but left pytest.fixture on those tests and everything passed.

@ericbuckley ericbuckley merged commit 4ee75ca into main Jun 3, 2025
15 checks passed
@ericbuckley ericbuckley deleted the fix/caching-default-algo-fixture branch June 3, 2025 15:36
ericbuckley added a commit that referenced this pull request Jun 3, 2025
## Description
Replacing lru_cache decorator on default_algorithm fixture with a
scope=session for reuse. Updating a handful of tests in test_link.py to
modify a copy of the default_algorithm object, rather than the original,
so we don't break subsequent tests using that same fixture.

## Additional Notes
The latest release of [pytest, 8.4.0, made
changes](https://docs.pytest.org/en/stable/changelog.html#pytest-8-4-0-2025-06-02)
to how fixtures are recognized and loaded. Using an lru_cache decorator
on top of a pytest.fixture, is now causing the harness to not see it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants