pytest-dev / pytest-dev/pytest-xdist

Serialization error with StrEnum obj

Open
#1,161 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.9k
Forks
288
Avg merge
9h 30m
Merged PRs (30d)
2

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided pytest-subtests example with pytest-xdist using -n 2, then inspect the referenced execnet gateway_base.py serialization code at lines 1655-1665. Confirm the failure with the StrEnum subtest message and add or update a regression test showing that the distributed run completes without DumpError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.