pytest-dev / pytest-dev/execnet

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

Open
#161 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted
Dominant language
Python
Stars
102
Forks
47
PR merge metrics
No merged PRs in 30d

Description

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.

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

Reproduce the failure with execnet, pytest-xdist, and teamcity-messages installed, starting from execnet's gateway_base.py and the ChannelFileWrite object in the traceback. Inspect teamcity/common.py where sys.stdout.encoding is read, then run the affected pytest-xdist tests with and without teamcity-messages. Done means the plugin loads without this AttributeError and the tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems
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.