Skip to content

pytest warnings: pytest-asyncio deprecation and pydantic field shadowing #707

@abrookins

Description

@abrookins

Issue Description

The test suite currently emits several warnings during pytest runs that, while not affecting functionality, are distracting and may indicate future compatibility issues.

Warnings Observed

1. pytest-asyncio Deprecation Warning

DeprecationWarning: The event_loop fixture provided by pytest-asyncio has been redefined in
/Users/andrew.brookins/src/redis-om-python/tests/conftest.py:20
Replacing the event_loop fixture with a custom implementation is deprecated
and will lead to errors in the future.
If you want to request an asyncio event loop with a scope other than function
scope, use the "scope" argument to the asyncio mark when marking the tests.
If you want to return different types of event loops, use the event_loop_policy
fixture.

2. Pydantic Field Shadowing Warning

UserWarning: Field name "dict" in "test_model_with_dict.<locals>.EmbeddedJsonModelWithDict" shadows an attribute in parent "EmbeddedJsonModel"
warnings.warn(

Steps to Reproduce

Run the test suite:

pytest

The warnings appear in the output during test execution.

Analysis

pytest-asyncio Warning

  • The current test suite uses a custom event_loop fixture in tests/conftest.py
  • pytest-asyncio now recommends using event_loop_policy fixtures or scope arguments instead
  • Critical: Attempts to fix this by modifying the event loop configuration break the Redis async connection handling throughout the test suite

Pydantic Warning

  • Test cases use a field named dict which shadows the built-in dict attribute
  • Located in tests/test_json_model.py and tests_sync/test_json_model.py in the test_model_with_dict functions

Impact

  • Low Priority: Warnings are cosmetic and don't affect test functionality
  • No Immediate Action Required: The test suite works correctly despite the warnings
  • Future Consideration: May need addressing if warnings become errors in future library versions

Investigation Notes

Extensive investigation revealed that:

  1. Any attempt to modify the pytest-asyncio configuration to eliminate the warning causes widespread test failures with "Event loop is closed" and "Future attached to a different loop" errors
  2. The current async architecture is tightly coupled to the existing event loop fixture
  3. The warnings appear to be harmless but indicate potential future compatibility issues

Recommendation

  • Short term: Leave warnings as-is since fixing them breaks functionality
  • Long term: Consider updating the async test architecture when upgrading pytest-asyncio versions
  • Monitor: Keep an eye on pytest-asyncio releases for better migration paths

Environment

  • Python 3.12.9
  • pytest-asyncio 0.24.0
  • pydantic 2.x

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions