Skip to content

Allow pytest 9#986

Merged
auvipy merged 1 commit intocelery:mainfrom
cjwatson:pytest-9
Mar 2, 2026
Merged

Allow pytest 9#986
auvipy merged 1 commit intocelery:mainfrom
cjwatson:pytest-9

Conversation

@cjwatson
Copy link
Contributor

@cjwatson cjwatson commented Jan 1, 2026

https://docs.pytest.org/en/stable/deprecations.html#applying-a-mark-to-a-fixture-function notes that applying a mark to a fixture function never had any effect. It raises an exception during test collection with pytest 9.

https://docs.pytest.org/en/stable/deprecations.html#applying-a-mark-to-a-fixture-function
notes that applying a mark to a fixture function never had any effect.
It raises an exception during test collection with pytest 9.
@codecov
Copy link

codecov bot commented Jan 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.28%. Comparing base (3539e7d) to head (78d62f4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #986      +/-   ##
==========================================
+ Coverage   88.18%   88.28%   +0.09%     
==========================================
  Files          32       32              
  Lines        1007     1007              
  Branches      105      105              
==========================================
+ Hits          888      889       +1     
+ Misses        101      100       -1     
  Partials       18       18              

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

@cclauss
Copy link
Contributor

cclauss commented Jan 1, 2026

@cjwatson
Copy link
Contributor Author

cjwatson commented Jan 1, 2026

I'm not sure I understand the question, sorry. The rule that you can't use marks on fixtures comes from pytest itself.

class test_DatabaseSchedulerFromAppConf(SchedulerCase):
Scheduler = TrackingScheduler

@pytest.mark.django_db
Copy link
Member

Choose a reason for hiding this comment

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

why removing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The link I posted in the issue description explains it. This is a mark applied to a fixture function. With pytest<9 it was a no-op; with pytest>=9 it is an error. It doesn't matter what the mark is.

The mark that actually matters is the one applied to the class, which my PR doesn't touch.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the test suite and test dependency constraints to remain compatible with pytest 9’s stricter collection behavior around marks applied to fixture functions.

Changes:

  • Removed @pytest.mark.django_db decorators from autouse fixture functions (where they are ineffective and now error under pytest 9).
  • Relaxed the pytest upper bound for Python 3.9+ to allow pytest 9 (<10.0).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
t/unit/test_schedulers.py Removes django_db marks from fixture functions; the relevant test classes are already marked django_db.
requirements/test.txt Expands pytest version range for Python 3.9+ to permit pytest 9.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@cclauss cclauss left a comment

Choose a reason for hiding this comment

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

All three test classes have @pytest.mark.django_db decorators, so this looks good to me.

@auvipy auvipy merged commit 8da6571 into celery:main Mar 2, 2026
33 checks passed
@cjwatson cjwatson deleted the pytest-9 branch March 2, 2026 13:36
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.

4 participants