pytest-dev / pytest-dev/execnet

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

オープン
#161 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

execnet、pytest-xdist、teamcity-messagesをインストールした状態で、execnetのgateway_base.pyとトレースバックにあるChannelFileWriteオブジェクトから調査を開始し、障害を再現します。sys.stdout.encodingが読み取られているteamcity/common.pyを調べ、その後、影響を受けるpytest-xdistのテストをteamcity-messagesありとなしの両方で実行します。プラグインがこのAttributeErrorなしで読み込まれ、テストがパスすれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
distributed-systems
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。