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

-Werror-related test failures with pytest 8.x #9025

Open
1 task done
mgorny opened this issue Mar 15, 2024 · 7 comments · May be fixed by #9040
Open
1 task done

-Werror-related test failures with pytest 8.x #9025

mgorny opened this issue Mar 15, 2024 · 7 comments · May be fixed by #9040
Labels
bug V2 Bug related to Pydantic V2
Milestone

Comments

@mgorny
Copy link
Contributor

mgorny commented Mar 15, 2024

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

This is the final set of test failures with pytest-8:

FAILED tests/test_config.py::TestsBaseConfig::test_config_class_is_deprecated - pydantic.warnings.PydanticDeprecatedSince20: BaseConfig is deprecated. Use the `pydantic.ConfigDict` instead. Deprecated in Pydant...
FAILED tests/test_config.py::TestsBaseConfig::test_config_class_attributes_are_deprecated - pydantic.warnings.PydanticDeprecatedSince20: BaseConfig is deprecated. Use the `pydantic.ConfigDict` instead. Deprecated in Pydant...
FAILED tests/test_deprecated.py::test_parse_raw_pass - pydantic.warnings.PydanticDeprecatedSince20: `load_str_bytes` is deprecated. Deprecated in Pydantic V2.0 to be removed in V3.0. Se...
FAILED tests/test_deprecated.py::test_parse_raw_pass_fail - pydantic.warnings.PydanticDeprecatedSince20: `load_str_bytes` is deprecated. Deprecated in Pydantic V2.0 to be removed in V3.0. Se...
FAILED tests/test_deprecated.py::test_field_include_deprecation - pydantic.warnings.PydanticDeprecatedSince20: Using extra keyword arguments on `Field` is deprecated and will be removed. Use `json...
FAILED tests/test_deprecated.py::test_parse_file - pydantic.warnings.PydanticDeprecatedSince20: `load_file` is deprecated. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pyd...
FAILED tests/test_deprecated.py::test_deprecated_module - pydantic.warnings.PydanticDeprecatedSince20: `schema_of` is deprecated. Use `pydantic.TypeAdapter.json_schema` instead. Deprecated...
FAILED tests/test_json_schema.py::test_callable_fallback_with_non_serializable_default[Cannot generate a JsonSchema for core_schema.CallableSchema \\[skipped-choice\\]] - pydantic.json_schema.PydanticJsonSchemaWarning: Default value <function test_callable_fallback_with_non_serializable_default.<loca...
FAILED tests/test_json_schema.py::test_callable_fallback_with_non_serializable_default[Default value .* is not JSON serializable; excluding default from JSON schema \\[non-serializable-default\\]] - pydantic.json_schema.PydanticJsonSchemaWarning: Cannot generate a JsonSchema for core_schema.CallableSchema [skipped-choice]
FAILED tests/test_validators.py::test_root_validator_allow_reuse_same_field - pydantic.warnings.PydanticDeprecatedSince20: Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to ...

FWIU they happen because of filterwarnings = error. This is because prior to pytest-8, pytest.warns() would always consume all warnings. With pytest >= 8, it consumes only matching warnings and reemits the rest, so they get caught by -Werror.

Example Code

No response

Python, Pydantic & OS Version

pydantic version: 2.7.0a1
        pydantic-core version: 2.16.3
          pydantic-core build: profile=release pgo=true
                 install path: /home/mgorny/git/pydantic/pydantic
               python version: 3.11.8 (main, Feb 11 2024, 17:30:38) [GCC 13.2.1 20240113]
                     platform: Linux-6.7.9-gentoo-dist-x86_64-AMD_Ryzen_5_3600_6-Core_Processor-with-glibc2.39
             related packages: typing_extensions-4.10.0
                       commit: 604bbd3f
@mgorny mgorny added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Mar 15, 2024
@sydney-runkle
Copy link
Member

@mgorny,

Thanks for reporting these. Are you interested in opening another PR to help us fix these issues?

@sydney-runkle sydney-runkle removed the pending Awaiting a response / confirmation label Mar 17, 2024
@mgorny
Copy link
Contributor Author

mgorny commented Mar 18, 2024

I'm afraid I wasn't able to find a good solution here.

@sydney-runkle
Copy link
Member

@mgorny,

No worries. We can take a look after the 2.7 release! Adding this to the 2.8 milestone.

@sydney-runkle sydney-runkle added this to the v2.8.0 milestone Mar 18, 2024
@mgorny
Copy link
Contributor Author

mgorny commented Mar 18, 2024

Maybe I'll try experimenting a bit later today, if I feel better.

@mgorny
Copy link
Contributor Author

mgorny commented Mar 18, 2024

Ok, so I suppose we could workaround all of them by adding @pytest.mark.filterwarnings to individual tests. But in some cases, it seems like we are ending up throwing "deep" warnings from implementation of deprecated functions — I suppose I'm going to try changing that to avoid spurious warnings.

@mgorny mgorny linked a pull request Mar 18, 2024 that will close this issue
5 tasks
@mgorny
Copy link
Contributor Author

mgorny commented Mar 18, 2024

@sydney-runkle, I've made a WIP #9040. I'd appreciate if you could take a look and let me know if that approach is acceptable.

@mgorny
Copy link
Contributor Author

mgorny commented Mar 18, 2024

Ok, a few questions:

    def test_config_class_is_deprecated(self):
>       with pytest.warns(
            PydanticDeprecatedSince20, match='Support for class-based `config` is deprecated, use ConfigDict instead.'
        ):
E       pydantic.warnings.PydanticDeprecatedSince20: BaseConfig is deprecated. Use the `pydantic.ConfigDict` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.7/migration/

Is there a point in emitting BaseConfig deprecation warning if all class-based configs are deprecated? I suppose I can either adjust the test to ignore the duplicate warning, or I could remove the BaseConfig deprecation warning and just leave "Support for class-based config is deprecated" to inform the user about that.

    def test_field_include_deprecation():
        m = '`include` is deprecated and does nothing. It will be removed, use `exclude` instead'
>       with pytest.warns(PydanticDeprecatedSince20, match=m):
E       pydantic.warnings.PydanticDeprecatedSince20: Using extra keyword arguments on `Field` is deprecated and will be removed. Use `json_schema_extra` instead. (Extra keys: 'include'). Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.7/migration/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V2 Bug related to Pydantic V2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants