pytest-dev / pytest-dev/execnet

AttributeError: 'ChannelFileWrite' object has no attribute 'encoding'

未关闭
#161 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug help wanted
主要语言
Python
星标
102
派生
47
PR 合并指标
30 天内没有已合并 PR

描述

When I try to run testsuite for pytest-xdist and both execnet and teamcity-messages are installed few tests fails with errors like:

__________________ TestRemoteControl.test_failures_somewhere ___________________

self = <test_looponfail.TestRemoteControl object at 0x7fffaa00c7c0>
pytester = <Pytester PosixPath('/tmp/pytest-of-marcel/pytest-10/test_failures_somewhere0')>

    def test_failures_somewhere(self, pytester: pytest.Pytester) -> None:
        item = pytester.getitem("def test_func():\n assert 0\n")
        control = RemoteControl(item.config)
        control.setup()
>       failures = control.runsession()

$(BLDDIR)/testing/test_looponfail.py:126:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  
$(INSTDIR)/usr/lib/python3.9/vendor-packages/xdist/looponfail.py:117: in runsession
    return self.channel.receive()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <Channel id=1 closed>, timeout = None

    def receive(self, timeout=None):
        """receive a data item that was sent from the other side.
        timeout: None [default] blocked waiting.  A positive number
        indicates the number of seconds after which a channel.TimeoutError
        exception will be raised if no item was received.
        Note that exceptions from the remotely executing code will be
        reraised as channel.RemoteError exceptions containing
        a textual representation of the remote traceback.
        """
        itemqueue = self._items
        if itemqueue is None:
            raise IOError("cannot receive(), channel has receiver callback")
        try:
            x = itemqueue.get(timeout=timeout) 
        except self.gateway.execmodel.queue.Empty:
            raise self.TimeoutError("no item after %r seconds" % timeout)
        if x is ENDMARKER:
            itemqueue.put(x)  # for other receivers
>           raise self._getremoteerror() or EOFError()
E           execnet.gateway_base.RemoteError: Traceback (most recent call last):
E             File "/usr/lib/python3.9/vendor-packages/execnet/gateway_base.py", line 1088, in executetask
E               function(channel, **kwargs)
E             File "$(INSTDIR)/usr/lib/python3.9/vendor-packages/xdist/looponfail.py", line 171, in init_worker_session
E               config = Config.fromdictargs(option_dict, list(args))
E             File "/usr/lib/python3.9/vendor-packages/_pytest/config/__init__.py", line 1110, in fromdictargs
E               config.parse(args, addopts=False)
E             File "/usr/lib/python3.9/vendor-packages/_pytest/config/__init__.py", line 1346, in parse
E               self._preparse(args, addopts=addopts)
E             File "/usr/lib/python3.9/vendor-packages/_pytest/config/__init__.py", line 1229, in _preparse
E               self.pluginmanager.load_setuptools_entrypoints("pytest11")
E             File "/usr/lib/python3.9/vendor-packages/pluggy/_manager.py", line 287, in load_setuptools_entrypoints
E               plugin = ep.load()
E             File "/usr/lib/python3.9/importlib/metadata.py", line 86, in load
E               module = import_module(match.group('module'))
E             File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
E               return _bootstrap._gcd_import(name[level:], package, level)
E             File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
E             File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
E             File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
E             File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
E             File "/usr/lib/python3.9/vendor-packages/_pytest/assertion/rewrite.py", line 168, in exec_module
E               exec(co, module.__dict__)
E             File "/usr/lib/python3.9/vendor-packages/teamcity/pytest_plugin.py", line 22, in <module>
E               from teamcity.common import convert_error_to_string, dump_test_stderr, dump_test_stdout
E             File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
E             File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
E             File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
E             File "/usr/lib/python3.9/vendor-packages/_pytest/assertion/rewrite.py", line 168, in exec_module
E               exec(co, module.__dict__)
E             File "/usr/lib/python3.9/vendor-packages/teamcity/common.py", line 19, in <module>
E               _sys_stdout_encoding = sys.stdout.encoding
E           AttributeError: 'ChannelFileWrite' object has no attribute 'encoding'

/usr/lib/python3.9/vendor-packages/execnet/gateway_base.py:749: RemoteError

With teamcity-messages uninstalled these tests pass.

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

在安装了 execnet、pytest-xdist 和 teamcity-messages 的情况下复现该故障,从 execnet 的 gateway_base.py 和 traceback 中的 ChannelFileWrite 对象入手。检查读取 sys.stdout.encoding 的 teamcity/common.py,然后分别在有和没有 teamcity-messages 的情况下运行受影响的 pytest-xdist 测试。插件能够在不出现此 AttributeError 的情况下加载且测试通过,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
distributed-systems
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。