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

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

Open
mtelka opened this issue Dec 10, 2022 · 3 comments
Open

Comments

@mtelka
Copy link
Contributor

mtelka commented Dec 10, 2022

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.

@RonnyPfannschmidt
Copy link
Member

Execnet indeed never was updated to the full new apis

@mtelka
Copy link
Contributor Author

mtelka commented Jul 17, 2024

Since pytest-xdist does not need teamcity-messages to run its tests then it is easy to avoid this issue: simply do not install (or load) the teamcity-messages pytest plugin during the pytest-xdist testing.

@RonnyPfannschmidt
Copy link
Member

the issue is valid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants