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

test_rich_console_ex Test fail: duplicate values #58

Open
sebix opened this issue Sep 11, 2022 · 5 comments
Open

test_rich_console_ex Test fail: duplicate values #58

sebix opened this issue Sep 11, 2022 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@sebix
Copy link

sebix commented Sep 11, 2022

On openSUSE Tumbleweed we are currently experiencing this test fail:

[  115s] =================================== FAILURES ===================================
[  115s] _____________________________ test_rich_console_ex _____________________________
[  115s] 
[  115s]     def test_rich_console_ex() -> None:
[  115s]         """Validate that ConsoleEx can capture output from print() calls."""
[  115s]         console = Console(record=True, redirect=True)
[  115s]         console.print("alpha")
[  115s]         print("beta")
[  115s]         sys.stdout.write("gamma\n")
[  115s]         sys.stderr.write("delta\n")
[  115s]         # While not supposed to happen we want to be sure that this will not raise
[  115s]         # an exception. Some libraries may still sometimes send bytes to the
[  115s]         # streams, notable example being click.
[  115s]         # sys.stdout.write(b"epsilon\n")  # type: ignore
[  115s]         proc = run("echo 123")
[  115s]         assert proc.stdout == "123\n"
[  115s]         text = console.export_text()
[  115s] >       assert text == "alpha\nbeta\ngamma\ndelta\n123\n"
[  115s] E       AssertionError: assert 'alpha\nbeta\...a\n123\n123\n' == 'alpha\nbeta\...ndelta\n123\n'
[  115s] E           alpha
[  115s] E           beta
[  115s] E         + beta
[  115s] E         + gamma
[  115s] E           gamma
[  115s] E           delta
[  115s] E         + delta...
[  115s] E         
[  115s] E         ...Full output truncated (3 lines hidden), use '-vv' to show
[  115s] 
[  115s] src/subprocess_tee/test/test_rich.py:23: AssertionError
[  115s] ----------------------------- Captured stdout call -----------------------------
[  115s] alpha
[  115s] beta
[  115s] gamma
[  115s] delta
[  115s] 123

Complete log (which also includes versions of all installed libraries):
log.txt

Do you know what the issue might be?

@ssbarnea
Copy link
Member

That is probably because you do not have PYTHONUNBUFFERED=1, which is kinda needed for ensuring the order of stdout/stderr. It is not required for using the library but to get the tests passing with expected order it is needed.

@sebix
Copy link
Author

sebix commented Sep 12, 2022

Unfortunately that doesn't fix the failure:

> PYTHONUNBUFFERED=1 pytest -k 'test_rich_console_ex'
============================================================================================================ test session starts ============================================================================================================
platform linux -- Python 3.10.6, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/abuild/rpmbuild/BUILD/subprocess-tee-0.3.5, configfile: setup.cfg, testpaths: src
collected 16 items / 14 deselected / 2 selected                                                                                                                                                                                             

src/subprocess_tee/test/test_rich.py F.                                                                                                                                                                                               [100%]

================================================================================================================= FAILURES ==================================================================================================================
___________________________________________________________________________________________________________ test_rich_console_ex ____________________________________________________________________________________________________________

    def test_rich_console_ex() -> None:
        """Validate that ConsoleEx can capture output from print() calls."""
        console = Console(record=True, redirect=True)
        console.print("alpha")
        print("beta")
        sys.stdout.write("gamma\n")
        sys.stderr.write("delta\n")
        # While not supposed to happen we want to be sure that this will not raise
        # an exception. Some libraries may still sometimes send bytes to the
        # streams, notable example being click.
        # sys.stdout.write(b"epsilon\n")  # type: ignore
        proc = run("echo 123")
        assert proc.stdout == "123\n"
        text = console.export_text()
>       assert text == "alpha\nbeta\ngamma\ndelta\n123\n"
E       AssertionError: assert 'alpha\nbeta\...a\n123\n123\n' == 'alpha\nbeta\...ndelta\n123\n'
E           alpha
E           beta
E         + beta
E         + gamma
E           gamma
E           delta
E         + delta...
E         
E         ...Full output truncated (3 lines hidden), use '-vv' to show

src/subprocess_tee/test/test_rich.py:23: AssertionError
----------------------------------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------------------------------

@dvzrv
Copy link
Contributor

dvzrv commented Nov 12, 2022

I'm seeing the same issue on Arch Linux and exporting PYTHONUNBUFFERED=1 also did not fix this for me.

python-subprocess-tee-0.3.5-4-x86_64-build.log
python-subprocess-tee-0.3.5-4-x86_64-check.log

@ssbarnea ssbarnea added the bug Something isn't working label Nov 24, 2022
@ssbarnea
Copy link
Member

ssbarnea commented Nov 24, 2022

A PR would be welcomed!

@ssbarnea ssbarnea added the help wanted Extra attention is needed label Nov 24, 2022
ssbarnea added a commit that referenced this issue Nov 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 help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants