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

Serialization error with StrEnum obj #1161

Open
yugokato opened this issue Dec 4, 2024 · 0 comments
Open

Serialization error with StrEnum obj #1161

yugokato opened this issue Dec 4, 2024 · 0 comments

Comments

@yugokato
Copy link

yugokato commented Dec 4, 2024

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.

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

No branches or pull requests

1 participant