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

[Windows] DuplicateStdout failed without "pytest -s" (RDT-96) #61

Open
hfudev opened this issue Feb 22, 2022 · 0 comments
Open

[Windows] DuplicateStdout failed without "pytest -s" (RDT-96) #61

hfudev opened this issue Feb 22, 2022 · 0 comments
Labels
bug Something isn't working windows windows only

Comments

@hfudev
Copy link
Member

hfudev commented Feb 22, 2022

error message without "-s"

pytest --junit-xml=./test_app_results.xml --port=COM25 --embedded-services esp --target=esp32
=============================================== test session starts ===============================================
platform win32 -- Python 3.8.0, pytest-7.0.1, pluggy-1.0.0
rootdir: C:\github_repos\idf-extra-components\test_app
plugins: embedded-0.6.0rc0
collected 1 item

test_app.py E                                                                                                [100%]

===================================================== ERRORS ======================================================
___________________________________________ ERROR at setup of test_app ____________________________________________

self = <pytest_embedded.plugin.PytestEmbedded object at 0x0000022693DC9E20>
fixturedef = <FixtureDef argname='serial' scope='function' baseid=''>
request = <SubRequest 'serial' for <Function test_app>>

    @pytest.hookimpl(tryfirst=True)
    def pytest_fixture_setup(self, fixturedef: FixtureDef[Any], request: SubRequest):
        if fixturedef.argname != 'serial':
            return

        # inject the cache into the serial kwargs
        kwargs = self._pytest_fixturedef_get_kwargs(fixturedef, request)
        _class_cli_options = kwargs['_fixture_classes_and_options']

        # compatible to multi-dut
        if isinstance(_class_cli_options, ClassCliOptions):
            iterable_class_cli_options = [_class_cli_options]
        else:
            iterable_class_cli_options = _class_cli_options

        for _item in iterable_class_cli_options:
            _item_cls = _item.classes.get('serial')
            _item_kwargs = _item.kwargs.get('serial')

            if _item_cls is None or _item_kwargs is None:
                continue

            if _item_cls.__name__ == 'IdfSerial':  # use str to avoid ImportError
                _item_kwargs['port_target_cache'] = self._port_target_cache
                _item_kwargs['port_app_cache'] = self._port_app_cache
            elif _item_cls.__name__ == 'EspSerial':  # use str to avoid ImportError
                _item_kwargs['port_target_cache'] = self._port_target_cache

>       return self._pytest_fixturedef_exec(fixturedef, request, kwargs)

<USER>\.espressif\python_env\idf5.0_py3.8_env\lib\site-packages\pytest_embedded\plugin.py:1089:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
<USER>\.espressif\python_env\idf5.0_py3.8_env\lib\site-packages\pytest_embedded\plugin.py:1052: in _pytest_fixturedef_exec
    result = call_fixture_func(fixturefunc, request, kwargs)
<USER>\.espressif\python_env\idf5.0_py3.8_env\lib\site-packages\pytest_embedded\plugin.py:335: in wrapper
    res = func(*args, **kwargs)
<USER>\.espressif\python_env\idf5.0_py3.8_env\lib\site-packages\pytest_embedded\plugin.py:904: in serial
    return cls(**_drop_none_kwargs(kwargs))
<USER>\.espressif\python_env\idf5.0_py3.8_env\lib\site-packages\pytest_embedded_serial_esp\serial.py:50: in __init__
    self.esp: esptool.ESPLoader = esptool.get_default_connected_device(
<USER>\.espressif\python_env\idf5.0_py3.8_env\lib\site-packages\esptool.py:118: in get_default_connected_device
    print("Serial port %s" % each_port)
<USER>\.espressif\python_env\idf5.0_py3.8_env\lib\site-packages\pytest_embedded\log.py:195: in write
    self.pexpect_proc.write(data)
<USER>\.espressif\python_env\idf5.0_py3.8_env\lib\site-packages\pytest_embedded\log.py:105: in write
    self.send(s)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pytest_embedded.log.PexpectProcess object at 0x0000022693E516D0>, s = b'\n'

    def send(self, s: AnyStr) -> int:
        """
        Write to the pexpect process and log.

        Args:
            s: bytes or str

        Returns:
            number of written bytes.
        """
        if not s:
            return 0

        s = self._coerce_send_string(s)
        self._log(s, 'send')

        # for pytest logging
        _temp = sys.stdout
        sys.stdout = self.STDOUT  # ensure the following print uses system sys.stdout

        _s = to_str(s)
        prefix = ''
        if self.source:
            prefix = f'[{self.source}] ' + prefix
        if self._with_timestamp:
            prefix = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + ' ' + prefix

        if not self._added_prefix:
            _s = prefix + _s
            self._added_prefix = True
        _s = _s.replace('\n', '\n' + prefix)
        if _s.endswith(prefix):
            _s = _s.rsplit(prefix, maxsplit=1)[0]
            self._added_prefix = False

>       sys.stdout.write(_s)
E       OSError: [WinError 6] The handle is invalid

<USER>\.espressif\python_env\idf5.0_py3.8_env\lib\site-packages\pytest_embedded\log.py:89: OSError
------------- generated xml file: C:\github_repos\idf-extra-components\test_app\test_app_results.xml --------------
============================================= short test summary info =============================================
ERROR test_app.py::test_app - OSError: [WinError 6] The handle is invalid
================================================ 1 error in 0.44s =================================================

Everything is fine with "-s"

@hfudev hfudev added the bug Something isn't working label Feb 22, 2022
@github-actions github-actions bot changed the title [Windows] DuplicateStdout failed without "pytest -s" [Windows] DuplicateStdout failed without "pytest -s" (RDT-96) Feb 22, 2022
@hfudev hfudev added the windows windows only label Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working windows windows only
Projects
None yet
Development

No branches or pull requests

1 participant