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

Passing StrEnum obj as msg causes serialization error in pytest-xdist #170

Closed
yugokato opened this issue Dec 4, 2024 · 2 comments
Closed

Comments

@yugokato
Copy link

yugokato commented Dec 4, 2024

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'>

I expected this to work as the value I passed is technically a string (MyEnum.FOO is of type str).

NOTE: I'm actually not sure if this should be handled by pytest-xdist (execnet) or pytest-subtests. I decided to open it as a pytest-subtests issue after seeing this comment.

Environment

  • Python 3.12
  • pytest==8.3.4
  • pytest-subtests==0.13.1
  • pytest-xdist==3.6.1
@nicoddemus
Copy link
Member

Thanks for the report, but this is actually related to xdist, as it is trying to serialize and send the object to the gateway. 👍

@yugokato
Copy link
Author

yugokato commented Dec 4, 2024

Will open this in pytest-xdist

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

2 participants