Skip to content

Serialization error with StrEnum obj #1161

Open
@yugokato

Description

@yugokato

pytest-xdist currently doesn't handle a StrEnum obj as str when it is serialized, which causes a "execnet.gateway_base.DumpError" error. The issue is seen when a StrEnum obj is passed as pytest-subtests subtest message.

Here is the minimum code to reproduce the issue:

from enum import StrEnum, auto

import pytest
from pytest_subtests import SubTests


class MyEnum(StrEnum):
    FOO = auto()


@pytest.mark.parametrize("p", range(2))
def test_something(subtests: SubTests, p):
    with subtests.test(MyEnum.FOO):
        pass

Running the above test with pytest-xdist (with -n 2, for example) results in the following error:

self = <execnet.gateway_base._Serializer object at 0x105c4d760>, obj = <MyEnum.FOO: 'foo'>

    def _save(self, obj: object) -> None:
        tp = type(obj)
        try:
            dispatch = self._dispatch[tp]
        except KeyError:
            methodname = "save_" + tp.__name__
            meth: Callable[[_Serializer, object], None] | None = getattr(
                self.__class__, methodname, None
            )
            if meth is None:
>               raise DumpError(f"can't serialize {tp}") from None
E               execnet.gateway_base.DumpError: can't serialize <enum 'MyEnum'>

Environment

  • Python 3.12
  • pytest==8.3.4
  • pytest-subtests==0.13.1
  • pytest-xdist==3.6.1

NOTE: I originally opened this issue in pytest-subtests but I was advised that it's actually a pytest-xdist issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions