Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Fix warnings due to deprecated test examples #273

Merged
merged 1 commit into from
Apr 24, 2024

Conversation

mansenfranzen
Copy link
Owner

@mansenfranzen mansenfranzen commented Apr 24, 2024

Type

Tests, Enhancement


Description

  • Removed the deprecated ConfigMembers class from configuration.py.
  • Updated FieldShowConstraintsIgnoreExtraKwargs to use correct keyword arguments.
  • Removed unnecessary env parameters from fields in multiple setting files to simplify the codebase.
  • Added a warning filter to test functions to handle deprecation warnings.

Changes walkthrough

Relevant files
Enhancement
configuration.py
Remove Deprecated Code and Fix Keyword Argument in Configuration

tests/roots/test-base/target/configuration.py

  • Removed deprecated class ConfigMembers.
  • Updated FieldShowConstraintsIgnoreExtraKwargs to use json_schema_extra
    instead of a non-existing keyword argument.
  • +1/-9     
    example_setting.py
    Simplify Field Definitions in Example Settings                     

    tests/roots/test-base/target/example_setting.py

    • Removed env parameter from field_with_validator_and_alias.
    +1/-1     
    usage_automodule.py
    Simplify Field Definitions in AutoModule Settings               

    tests/roots/test-base/target/usage_automodule.py

    • Removed env parameter from field_with_validator_and_alias.
    +1/-1     
    usage_setting.py
    Simplify Field Definitions in Usage Settings                         

    tests/roots/test-base/target/usage_setting.py

    • Removed env parameter from field_with_validator_and_alias.
    +1/-1     
    Tests
    test_inspection.py
    Add Warning Filter to Test Inspection                                       

    tests/test_inspection.py

  • Added a decorator to ignore Pydantic JSON schema warnings in a test
    function.
  • +1/-0     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @mansenfranzen mansenfranzen merged commit 65ed9cc into main Apr 24, 2024
    42 checks passed
    @mansenfranzen mansenfranzen deleted the fix_test_warnings branch April 24, 2024 09:40
    @github-actions github-actions bot added enhancement New feature or request tests labels Apr 24, 2024
    Copy link
    Contributor

    PR Description updated to latest commit (1658eea)

    Copy link
    Contributor

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are straightforward and localized to specific parts of the code, mainly involving the removal of deprecated features and updating method arguments. The PR is well-documented and the changes are clear.

    🧪 Relevant tests

    No

    🔍 Possible issues

    No

    🔒 Security concerns

    No

    Code feedback:
    relevant filetests/roots/test-base/target/configuration.py
    suggestion      

    Consider validating the json_schema_extra dictionary to ensure it contains only expected keys. This can prevent potential bugs if unexpected keys are passed. [important]

    relevant linefield: int = Field(1, ge=0, le=100, json_schema_extra=dict(on_existing_kwarg=1))

    relevant filetests/roots/test-base/target/example_setting.py
    suggestion      

    Ensure that removing the env parameter does not affect the environment variable mapping which might be used elsewhere in your application. [important]

    relevant linefield_with_validator_and_alias: str = Field('FooBar', alias='BarFoo')

    relevant filetests/test_inspection.py
    suggestion      

    Add a comment explaining why the deprecation warning is ignored in this specific test case to maintain clarity for future maintenance. [medium]

    relevant line@pytest.mark.filterwarnings('ignore::pydantic.json_schema.PydanticJsonSchemaWarning')


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    @github-actions github-actions bot mentioned this pull request Apr 24, 2024
    Copy link
    Contributor

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Bug
    Correct the keyword argument for additional JSON schema specifications in a Pydantic field.

    Replace the json_schema_extra dictionary with the correct keyword argument for the
    Pydantic Field function. The correct keyword is schema_extra, not json_schema_extra.

    tests/roots/test-base/target/configuration.py [477]

    -field: int = Field(1, ge=0, le=100, json_schema_extra=dict(on_existing_kwarg=1))
    +field: int = Field(1, ge=0, le=100, schema_extra=dict(on_existing_kwarg=1))
     
    Enhancement
    Improve the precision of the ignored warnings in tests to avoid suppressing unintended warnings.

    Specify the exact warning to be ignored using pytest.mark.filterwarnings. Replace the
    general warning class with a more specific warning message or class to avoid suppressing
    unintended warnings.

    tests/test_inspection.py [137]

    -@pytest.mark.filterwarnings('ignore::pydantic.json_schema.PydanticJsonSchemaWarning')
    +@pytest.mark.filterwarnings('ignore:specific warning message or class')
     
    Maintainability
    Ensure that the new class configuration matches or improves upon the configuration of the class it replaces.

    Ensure that the ConfigSignaturePrefix class includes necessary configurations or methods
    if it is intended to replace the ConfigMembers class, which had specific configurations.

    tests/roots/test-base/target/configuration.py [319-321]

     class ConfigSignaturePrefix(BaseModel):
         """ConfigSignaturePrefix."""
    +    class Config:
    +        frozen = False
    +        title = 'FooBar'
     
    Refactor common field definitions into a base class or module to enhance maintainability and consistency.

    Consistency in field definitions across different modules should be maintained. If
    field_with_validator_and_alias is defined similarly in multiple files, consider creating a
    base class or a common module to define such fields to avoid duplication and maintain
    consistency.

    tests/roots/test-base/target/usage_automodule.py [17]

    -field_with_validator_and_alias: str = Field('FooBar', alias='BarFoo')
    +# Assuming a common base class or module named CommonFields
    +from common_module import CommonFields
    +class AutoModuleSettings(BaseSettings, CommonFields):
    +    pass
     
    Best practice
    Verify and update documentation or tests to reflect configuration changes in fields.

    If the removal of the env parameter from field_with_validator_and_alias was intentional to
    simplify the configuration, ensure that this change is reflected in the corresponding
    documentation or tests.

    tests/roots/test-base/target/example_setting.py [17]

    -field_with_validator_and_alias: str = Field('FooBar', alias='BarFoo')
    +field_with_validator_and_alias: str = Field('FooBar', alias='BarFoo')  # Ensure documentation reflects this change
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    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.

    1 participant