Skip to content

Fix pytest class-scoped fixture deprecation warning in extract_permissions tests - #71002

Merged
potiuk merged 1 commit into
apache:mainfrom
eladkal:warn
Aug 3, 2026
Merged

Fix pytest class-scoped fixture deprecation warning in extract_permissions tests#71002
potiuk merged 1 commit into
apache:mainfrom
eladkal:warn

Conversation

@eladkal

@eladkal eladkal commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Running scripts/tests/ci/prek/test_extract_permissions.py surfaces:

=========================================================================================================== warnings summary ============================================================================================================
tests/ci/prek/test_extract_permissions.py::TestExtractAllPermissions::test_extracts_non_empty_result
tests/ci/prek/test_extract_permissions.py::TestRenderRst::test_rst_contains_auto_generated_marker
  /Users/eladkal/Projects/airflow/.venv/lib/python3.12/site-packages/_pytest/fixtures.py:1313: PytestRemovedIn10Warning: Class-scoped fixture defined as instance method is deprecated.
  Instance attributes set in this fixture will NOT be visible to test methods,
  as each test gets a new instance while the fixture runs only once per class.
  Use @classmethod decorator and set attributes on cls instead.
  See https://docs.pytest.org/en/stable/deprecations.html#class-scoped-fixture-as-instance-method
    fixturefunc = resolve_fixture_function(fixturedef, request)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================================================================== 1017 passed, 2 warnings in 10.58s ===================================================================================================

for the class-scoped all_entries fixture in TestExtractAllPermissions
and the rst_content fixture in TestRenderRst. pytest 9.1 deprecates
this pattern because attributes set on self in a class-scoped fixture
aren't visible to test methods — pytest creates a new instance per
test while the fixture runs once per class — and the warning will
become an error in pytest 10.

Both fixtures here just return a computed value and never touch self,
so the fix is mechanical: decorate each with @classmethod and take
cls instead of self, per pytest's documented migration path.

No test behavior changes — all 70 tests in the file still pass with
no warnings.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude (Sonnet 4.5)

Generated-by: Claude (Sonnet 4.5) following the guidelines

…sions tests

pytest 9.1 deprecates defining a class-scoped fixture as a plain
instance method, since attributes set on self in the fixture aren't
visible to test methods (each test gets a new instance while the
fixture runs once per class). test_extract_permissions.py had two
such fixtures, all_entries and rst_content, triggering
PytestRemovedIn10Warning on every run. Neither fixture actually
relied on self, so marking them as @classmethod removes the warning
with no behavior change.
@potiuk
potiuk merged commit fb99b1d into apache:main Aug 3, 2026
65 checks passed
@eladkal
eladkal deleted the warn branch August 4, 2026 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants