Skip to content

2.18.2: pytest fails in 3 units #1302

@kloczek

Description

@kloczek

I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

  • python3 -sBm build -w --no-isolation
  • because I'm calling build with --no-isolation I'm using during all processes only locally installed modules
  • install .whl file in </install/prefix> using installer module
  • run pytest with $PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>
  • build is performed in env which is cut off from access to the public network (pytest is executed with -m "not network")

Python 3.10.14 and pytest 8.2.1.

Here is pytest output:
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-pydantic-core-2.18.2-2.fc37.x86_64/usr/lib64/python3.10/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-pydantic-core-2.18.2-2.fc37.x86_64/usr/lib/python3.10/site-packages
+ /usr/bin/pytest -ra -m 'not network'
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.10.14, pytest-8.2.1, pluggy-1.5.0
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=True warmup_iterations=100000)
rootdir: /home/tkloczko/rpmbuild/BUILD/pydantic-core-2.18.2
configfile: pyproject.toml
testpaths: tests
plugins: cov-4.1.0, hypothesis-6.100.0, anyio-4.3.0, timeout-2.3.1, benchmark-4.0.0, mock-3.14.0
timeout: 30.0s
timeout method: signal
timeout func_only: False
collected 4402 items

tests/benchmarks/test_complete_benchmark.py ..........                                                                                                                                [  0%]
tests/benchmarks/test_micro_benchmarks.py ...................................................................................................................                         [  2%]
tests/benchmarks/test_nested_benchmark.py ..                                                                                                                                          [  2%]
tests/benchmarks/test_serialization_micro.py ..............................                                                                                                           [  3%]
tests/serializers/test_any.py ...............................s...................................................s..                                                                  [  5%]
tests/serializers/test_bytes.py ................                                                                                                                                      [  5%]
tests/serializers/test_dataclasses.py .....x                                                                                                                                          [  6%]
tests/serializers/test_datetime.py ..................                                                                                                                                 [  6%]
tests/serializers/test_decimal.py .......                                                                                                                                             [  6%]
tests/serializers/test_definitions.py ........                                                                                                                                        [  6%]
tests/serializers/test_definitions_recursive.py .....                                                                                                                                 [  6%]
tests/serializers/test_dict.py ...............................                                                                                                                        [  7%]
tests/serializers/test_enum.py .....                                                                                                                                                  [  7%]
tests/serializers/test_format.py ...............                                                                                                                                      [  8%]
tests/serializers/test_functions.py ................................                                                                                                                  [  8%]
tests/serializers/test_generator.py ......                                                                                                                                            [  8%]
tests/serializers/test_json.py ....                                                                                                                                                   [  8%]
tests/serializers/test_json_or_python.py ..                                                                                                                                           [  9%]
tests/serializers/test_list_tuple.py ........................................................................                                                                         [ 10%]
tests/serializers/test_literal.py .....                                                                                                                                               [ 10%]
tests/serializers/test_misc.py ..                                                                                                                                                     [ 10%]
tests/serializers/test_model.py .....................................................                                                                                                 [ 12%]
tests/serializers/test_model_root.py ........                                                                                                                                         [ 12%]
tests/serializers/test_none.py ............................                                                                                                                           [ 12%]
tests/serializers/test_nullable.py .                                                                                                                                                  [ 12%]
tests/serializers/test_other.py .......                                                                                                                                               [ 13%]
tests/serializers/test_pickling.py .....                                                                                                                                              [ 13%]
tests/serializers/test_serialize_as_any.py ....                                                                                                                                       [ 13%]
tests/serializers/test_set_frozenset.py .......                                                                                                                                       [ 13%]
tests/serializers/test_simple.py ..........................s.........                                                                                                                 [ 14%]
tests/serializers/test_string.py ..........                                                                                                                                           [ 14%]
tests/serializers/test_timedelta.py ...s                                                                                                                                              [ 14%]
tests/serializers/test_typed_dict.py ...........................                                                                                                                      [ 15%]
tests/serializers/test_union.py .................................................................................                                                                     [ 16%]
tests/serializers/test_url.py ..........                                                                                                                                              [ 17%]
tests/serializers/test_uuid.py .......                                                                                                                                                [ 17%]
tests/test_build.py ..........s......                                                                                                                                                 [ 17%]
tests/test_config.py ..............                                                                                                                                                   [ 18%]
tests/test_docstrings.py ss                                                                                                                                                           [ 18%]
tests/test_errors.py .........................................................................................................................................................s...... [ 21%]
..........................                                                                                                                                                            [ 22%]
tests/test_garbage_collection.py ...                                                                                                                                                  [ 22%]
tests/test_hypothesis.py ...........                                                                                                                                                  [ 22%]
tests/test_isinstance.py .....                                                                                                                                                        [ 22%]
tests/test_json.py .............................................                                                                                                                      [ 23%]
tests/test_misc.py ................                                                                                                                                                   [ 24%]
tests/test_schema_functions.py ..........................................................................                                                                             [ 25%]
tests/test_strict.py ....................................                                                                                                                             [ 26%]
tests/test_typing.py ..........                                                                                                                                                       [ 26%]
tests/test_tzinfo.py ............                                                                                                                                                     [ 27%]
tests/test_validate_strings.py ....................                                                                                                                                   [ 27%]
tests/test_validation_context.py ...........                                                                                                                                          [ 27%]
tests/validators/test_arguments.py ..............s..s....s.........s.sssssss........ssssss.........sss......s..s.............s...sss.....s...s......ssss.....sss...sss.....sssss..... [ 31%]
...                                                                                                                                                                                   [ 31%]
tests/validators/test_bool.py .......................................                                                                                                                 [ 32%]
tests/validators/test_bytes.py ............................                                                                                                                           [ 32%]
tests/validators/test_call.py ..........................                                                                                                                              [ 33%]
tests/validators/test_callable.py ..............                                                                                                                                      [ 33%]
tests/validators/test_chain.py ............                                                                                                                                           [ 33%]
tests/validators/test_custom_error.py ......                                                                                                                                          [ 34%]
tests/validators/test_dataclasses.py .......s..sss........sssss......s...........................................................................................................     [ 37%]
tests/validators/test_date.py ......................................................................................................                                                  [ 39%]
tests/validators/test_datetime.py ..............................FF...............................................F......................                                              [ 41%]
tests/validators/test_decimal.py .................................................................................................................................................... [ 45%]
........................................                                                                                                                                              [ 46%]
tests/validators/test_definitions.py ...........                                                                                                                                      [ 46%]
tests/validators/test_definitions_recursive.py ....................................                                                                                                   [ 47%]
tests/validators/test_dict.py ..............................                                                                                                                          [ 47%]
tests/validators/test_enums.py ...........                                                                                                                                            [ 48%]
tests/validators/test_float.py ...................................................................................................................................................... [ 51%]
......................                                                                                                                                                                [ 52%]
tests/validators/test_frozenset.py .......................................................................                                                                            [ 53%]
tests/validators/test_function.py .........................................................                                                                                           [ 54%]
tests/validators/test_generator.py ......................................                                                                                                             [ 55%]
tests/validators/test_int.py ........................................................................................................................................................ [ 59%]
.............................................................                                                                                                                         [ 60%]
tests/validators/test_is_instance.py .................................                                                                                                                [ 61%]
tests/validators/test_is_subclass.py .............                                                                                                                                    [ 61%]
tests/validators/test_json.py .................................                                                                                                                       [ 62%]
tests/validators/test_json_or_python.py .                                                                                                                                             [ 62%]
tests/validators/test_lax_or_strict.py ..                                                                                                                                             [ 62%]
tests/validators/test_list.py ..............................................................................................                                                          [ 64%]
tests/validators/test_literal.py ............................................                                                                                                         [ 65%]
tests/validators/test_model.py .........................................                                                                                                              [ 66%]
tests/validators/test_model_fields.py ............................................................................................................................................... [ 69%]
...............................................................                                                                                                                       [ 71%]
tests/validators/test_model_init.py ..............                                                                                                                                    [ 71%]
tests/validators/test_model_root.py .........                                                                                                                                         [ 71%]
tests/validators/test_none.py ..                                                                                                                                                      [ 71%]
tests/validators/test_nullable.py ...                                                                                                                                                 [ 71%]
tests/validators/test_pickling.py ...                                                                                                                                                 [ 72%]
tests/validators/test_set.py .........................................................................                                                                                [ 73%]
tests/validators/test_string.py .....................................................................................................                                                 [ 75%]
tests/validators/test_tagged_union.py ................................................                                                                                                [ 77%]
tests/validators/test_time.py ...................................................................................                                                                     [ 78%]
tests/validators/test_timedelta.py ...............................................................................s                                                                   [ 80%]
tests/validators/test_tuple.py ......................................................................................                                                                 [ 82%]
tests/validators/test_typed_dict.py ................................................................................................................................................. [ 86%]
.........                                                                                                                                                                             [ 86%]
tests/validators/test_union.py ....................................................x.............                                                                                     [ 87%]
tests/validators/test_url.py ........................................................................................................................................................ [ 91%]
..................................................................................................................................................................................... [ 95%]
....                                                                                                                                                                                  [ 95%]
tests/validators/test_uuid.py .................................................................................                                                                       [ 97%]
tests/validators/test_with_default.py ...........................................................................................................................                     [100%]

========================================================================================= FAILURES ==========================================================================================
_______________________________________________________________________________________ test_keep_tz ________________________________________________________________________________________

    def test_keep_tz():
        tz = pytz.timezone('Europe/London')
        dt = tz.localize(datetime(2022, 6, 14, 12, 13, 14))
        v = SchemaValidator({'type': 'datetime'})

        output = v.validate_python(dt)
        assert output == dt

        # dst object is unaffected by validation
>       assert output.tzinfo.dst(datetime(2022, 6, 1)) == timedelta(seconds=3600)
E       AssertionError: assert datetime.timedelta(0) == datetime.timedelta(seconds=3600)
E        +  where datetime.timedelta(0) = <bound method StaticTzInfo.dst of <StaticTzInfo 'Europe/London'>>(datetime.datetime(2022, 6, 1, 0, 0))
E        +    where <bound method StaticTzInfo.dst of <StaticTzInfo 'Europe/London'>> = <StaticTzInfo 'Europe/London'>.dst
E        +      where <StaticTzInfo 'Europe/London'> = datetime.datetime(2022, 6, 14, 12, 13, 14, tzinfo=<StaticTzInfo 'Europe/London'>).tzinfo
E        +    and   datetime.datetime(2022, 6, 1, 0, 0) = datetime(2022, 6, 1)
E        +  and   datetime.timedelta(seconds=3600) = timedelta(seconds=3600)

tests/validators/test_datetime.py:92: AssertionError
____________________________________________________________________________________ test_keep_tz_bound _____________________________________________________________________________________

    def test_keep_tz_bound():
        tz = pytz.timezone('Europe/London')
        dt = tz.localize(datetime(2022, 6, 14, 12, 13, 14))
        v = SchemaValidator({'type': 'datetime', 'gt': datetime(2022, 1, 1)})

        output = v.validate_python(dt)
        assert output == dt

        # dst object is unaffected by validation
>       assert output.tzinfo.dst(datetime(2022, 6, 1)) == timedelta(hours=1)
E       AssertionError: assert datetime.timedelta(0) == datetime.timedelta(seconds=3600)
E        +  where datetime.timedelta(0) = <bound method StaticTzInfo.dst of <StaticTzInfo 'Europe/London'>>(datetime.datetime(2022, 6, 1, 0, 0))
E        +    where <bound method StaticTzInfo.dst of <StaticTzInfo 'Europe/London'>> = <StaticTzInfo 'Europe/London'>.dst
E        +      where <StaticTzInfo 'Europe/London'> = datetime.datetime(2022, 6, 14, 12, 13, 14, tzinfo=<StaticTzInfo 'Europe/London'>).tzinfo
E        +    and   datetime.datetime(2022, 6, 1, 0, 0) = datetime(2022, 6, 1)
E        +  and   datetime.timedelta(seconds=3600) = timedelta(hours=1)

tests/validators/test_datetime.py:105: AssertionError
________________________________________________________________________________ test_datetime_past_timezone ________________________________________________________________________________

    def test_datetime_past_timezone():
        v = SchemaValidator(core_schema.datetime_schema(now_utc_offset=0, now_op='past'))
        now_utc = datetime.now(timezone.utc) - timedelta(seconds=1)
        assert v.isinstance_python(now_utc)
        # "later" in the day
        assert v.isinstance_python(now_utc.astimezone(pytz.timezone('Europe/Istanbul')))
        # "earlier" in the day
        assert v.isinstance_python(now_utc.astimezone(pytz.timezone('America/Los_Angeles')))

        soon_utc = now_utc + timedelta(minutes=1)
        assert not v.isinstance_python(soon_utc)

        # "later" in the day
        assert not v.isinstance_python(soon_utc.astimezone(pytz.timezone('Europe/Istanbul')))
        # "earlier" in the day
        assert not v.isinstance_python(soon_utc.astimezone(pytz.timezone('America/Los_Angeles')))

        # input value is timezone naive, so we do a dumb comparison in these terms the istanbul time is later so fails
        # wile the LA time is earlier so passes
        assert not v.isinstance_python(soon_utc.astimezone(pytz.timezone('Europe/Istanbul')).replace(tzinfo=None))
>       assert v.isinstance_python(soon_utc.astimezone(pytz.timezone('America/Los_Angeles')).replace(tzinfo=None))
E       assert False
E        +  where False = <built-in method isinstance_python of pydantic_core._pydantic_core.SchemaValidator object at 0x55c5cd3aa730>(datetime.datetime(2024, 5, 26, 19, 45, 50, 718779))
E        +    where <built-in method isinstance_python of pydantic_core._pydantic_core.SchemaValidator object at 0x55c5cd3aa730> = SchemaValidator(title="datetime", validator=Datetime(\n    DateTimeValidator {\n        strict: false,\n        constrain...None,\n            },\n        ),\n        microseconds_precision: Truncate,\n    },\n), definitions=[], cache_strings=True).isinstance_python
E        +    and   datetime.datetime(2024, 5, 26, 19, 45, 50, 718779) = <built-in method replace of datetime.datetime object at 0x7f3b4bdd3900>(tzinfo=None)
E        +      where <built-in method replace of datetime.datetime object at 0x7f3b4bdd3900> = datetime.datetime(2024, 5, 26, 19, 45, 50, 718779, tzinfo=<StaticTzInfo 'America/Los_Angeles'>).replace
E        +        where datetime.datetime(2024, 5, 26, 19, 45, 50, 718779, tzinfo=<StaticTzInfo 'America/Los_Angeles'>) = <built-in method astimezone of datetime.datetime object at 0x7f3b4bdd3420>(<StaticTzInfo 'America/Los_Angeles'>)
E        +          where <built-in method astimezone of datetime.datetime object at 0x7f3b4bdd3420> = datetime.datetime(2024, 5, 26, 19, 45, 50, 718779, tzinfo=datetime.timezone.utc).astimezone
E        +          and   <StaticTzInfo 'America/Los_Angeles'> = <function timezone at 0x7f3b4b40c160>('America/Los_Angeles')
E        +            where <function timezone at 0x7f3b4b40c160> = pytz.timezone

tests/validators/test_datetime.py:340: AssertionError
========================================================================================= XFAILURES =========================================================================================
_______________________________________________________________________________ test_extra_custom_serializer ________________________________________________________________________________

    @pytest.mark.xfail(reason='dataclasses do not serialize extras')
    def test_extra_custom_serializer():
        @dataclasses.dataclass
        class Model:
            pass

        schema = core_schema.dataclass_schema(
            Model,
            core_schema.dataclass_args_schema(
                'Model',
                [],
                extra_behavior='allow',
                # extras_schema=core_schema.any_schema(
                #     serialization=core_schema.plain_serializer_function_ser_schema(
                #         lambda v: v + ' bam!',
                #     )
                # )
            ),
            [],
        )
        s = SchemaSerializer(schema)
        v = SchemaValidator(schema)

        m = v.validate_python({'extra': 'extra'})

>       assert s.to_python(m) == {'extra': 'extra bam!'}
E       AssertionError: assert {} == {'extra': 'extra bam!'}
E
E         Right contains 1 more item:
E         {'extra': 'extra bam!'}
E         Use -v to get more diff

tests/serializers/test_dataclasses.py:194: AssertionError
________________________________________________ test_smart_union_json_string_types_str_first[schema0-12345678-1234-5678-1234-567812345678] _________________________________________________

schema = {'type': 'uuid'}, input_value = '12345678-1234-5678-1234-567812345678'

    @pytest.mark.parametrize(
        ('schema', 'input_value'),
        (
            pytest.param(
                core_schema.uuid_schema(),
                '12345678-1234-5678-1234-567812345678',
                marks=pytest.mark.xfail(reason='TODO: V3'),
            ),
            (core_schema.date_schema(), '2020-01-01'),
            (core_schema.time_schema(), '00:00:00'),
            (core_schema.datetime_schema(), '2020-01-01:00:00:00'),
            (core_schema.url_schema(), 'https://foo.com'),
            (core_schema.multi_host_url_schema(), 'https://bar.com,foo.com'),
        ),
    )
    def test_smart_union_json_string_types_str_first(schema: core_schema.CoreSchema, input_value: str):
        # As above, but reversed order; str should always win
        validator = SchemaValidator(core_schema.union_schema([core_schema.str_schema(), schema]))
>       assert validator.validate_json(f'"{input_value}"') == input_value
E       assert UUID('12345678-1234-5678-1234-567812345678') == '12345678-1234-5678-1234-567812345678'
E        +  where UUID('12345678-1234-5678-1234-567812345678') = <built-in method validate_json of pydantic_core._pydantic_core.SchemaValidator object at 0x55c5cd6b5430>('"12345678-1234-5678-1234-567812345678"')
E        +    where <built-in method validate_json of pydantic_core._pydantic_core.SchemaValidator object at 0x55c5cd6b5430> = SchemaValidator(title="union[str,uuid]", validator=Union(\n    UnionValidator {\n        mode: Smart,\n        choices: [...stom_error: None,\n        strict: false,\n        name: "union[str,uuid]",\n    },\n), definitions=[], cache_strings=True).validate_json

tests/validators/test_union.py:572: AssertionError
================================================================================== short test summary info ==================================================================================
SKIPPED [1] tests/serializers/test_any.py:93: Path output different on windows
SKIPPED [1] tests/serializers/test_any.py:594: numpy is not installed
SKIPPED [1] tests/serializers/test_simple.py:127: numpy is not installed
SKIPPED [1] tests/serializers/test_timedelta.py:46: pandas not installed
SKIPPED [1] tests/test_build.py:64: unconditional skip
SKIPPED [1] tests/test_docstrings.py:15: Only on linux and macos
SKIPPED [1] tests/test_docstrings.py:28: Only on linux and macos
SKIPPED [1] tests/test_errors.py:514: This is the modern version used post 3.10.
SKIPPED [53] tests/conftest.py:47: JSON skipping ArgsKwargs
SKIPPED [1] tests/validators/test_timedelta.py:278: pandas not installed
XFAIL tests/serializers/test_dataclasses.py::test_extra_custom_serializer - dataclasses do not serialize extras
XFAIL tests/validators/test_union.py::test_smart_union_json_string_types_str_first[schema0-12345678-1234-5678-1234-567812345678] - TODO: V3
FAILED tests/validators/test_datetime.py::test_keep_tz - AssertionError: assert datetime.timedelta(0) == datetime.timedelta(seconds=3600)
FAILED tests/validators/test_datetime.py::test_keep_tz_bound - AssertionError: assert datetime.timedelta(0) == datetime.timedelta(seconds=3600)
FAILED tests/validators/test_datetime.py::test_datetime_past_timezone - assert False
================================================================== 3 failed, 4335 passed, 62 skipped, 2 xfailed in 14.75s ===================================================================
List of installed modules in build env:
Package            Version
------------------ -----------
attrs              23.2.0
build              1.2.1
dirty-equals       0.7.1.post0
exceptiongroup     1.1.3
hypothesis         6.100.0
importlib_metadata 7.1.0
iniconfig          2.0.0
installer          0.7.0
maturin            1.5.1
packaging          24.0
pluggy             1.5.0
py-cpuinfo         9.0.0
pyproject_hooks    1.0.0
pytest             8.2.1
pytest-benchmark   4.0.0
pytest-mock        3.14.0
pytest-timeout     2.3.1
python-dateutil    2.9.0.post0
sortedcontainers   2.4.0
tokenize_rt        5.2.0
tomli              2.0.1
typing_extensions  4.12.0
wheel              0.43.0
zipp               3.19.0

Please let me know if you need more details or want me to perform some diagnostics.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions