Skip to content

Strange test failure with pip 23.0.1 #587

@frenzymadness

Description

@frenzymadness

I know it's not your problem at all but you might know enough to help me with the following strange problem causing test_output_env_subprocess_error[color] to fail.

I maintain python-build RPM package in Fedora and it now fails to build since we updated pip from 22.3.1 to 23.0.1. The problem is this failing test:

=================================== FAILURES ===================================
___________________ test_output_env_subprocess_error[color] ____________________

mocker = <pytest_mock.plugin.MockerFixture object at 0x7f76f42d7f10>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f76f42bf5d0>
main_reload_styles = None
package_test_invalid_requirements = '/builddir/build/BUILD/build-0.10.0/tests/packages/test-invalid-requirements'
tmp_dir = '/tmp/python-build-test-0cztn5fn'
capsys = <_pytest.capture.CaptureFixture object at 0x7f76f43265d0>, color = True
stdout_body = ['\x1b[1m* Creating venv isolated environment...\x1b[0m', '\x1b[1m* Installing packages in isolated environment... (setuptools >= 42.0.0, this is invalid, wheel >= 0.36.0)\x1b[0m', '', '\x1b[2mTraceback (most recent call last):']
stdout_error = '\x1b[91mERROR\x1b[0m '

    @pytest.mark.pypy3323bug
    @pytest.mark.parametrize(
        ('color', 'stdout_error', 'stdout_body'),
        [
            (
                False,
                'ERROR ',
                [
                    '* Creating venv isolated environment...',
                    '* Installing packages in isolated environment... (setuptools >= 42.0.0, this is invalid, wheel >= 0.36.0)',
                    '',
                    'Traceback (most recent call last):',
                ],
            ),
            (
                True,
                '\33[91mERROR\33[0m ',
                [
                    '\33[1m* Creating venv isolated environment...\33[0m',
                    '\33[1m* Installing packages in isolated environment... '
                    '(setuptools >= 42.0.0, this is invalid, wheel >= 0.36.0)\33[0m',
                    '',
                    '\33[2mTraceback (most recent call last):',
                ],
            ),
        ],
        ids=['no-color', 'color'],
    )
    def test_output_env_subprocess_error(
        mocker,
        monkeypatch,
        main_reload_styles,
        package_test_invalid_requirements,
        tmp_dir,
        capsys,
        color,
        stdout_body,
        stdout_error,
    ):
        try:
            # do not inject hook to have clear output on capsys
            mocker.patch('colorama.init')
        except ModuleNotFoundError:  # colorama might not be available
            pass
    
        monkeypatch.delenv('NO_COLOR', raising=False)
        monkeypatch.setenv('FORCE_COLOR' if color else 'NO_COLOR', '')
    
        importlib.reload(build.__main__)  # reload module to set _STYLES
    
        with pytest.raises(SystemExit):
            build.__main__.main([package_test_invalid_requirements, '-o', tmp_dir])
        stdout, stderr = capsys.readouterr()
        stdout, stderr = stdout.splitlines(), stderr.splitlines()
    
        assert stdout[:4] == stdout_body
        assert stdout[-1].startswith(stdout_error)
    
>       assert len(stderr) == 1
E       assert 2 == 1
E        +  where 2 = len(["\x1b[31mERROR: Invalid requirement: 'this is invalid' (from line 1 of /tmp/build-reqs-ae11gsg7.txt)\x1b[0m\x1b[31m", '\x1b[0m'])

tests/test_main.py:371: AssertionError
=========================== short test summary info ============================
FAILED tests/test_main.py::test_output_env_subprocess_error[color] - assert 2...
===== 1 failed, 113 passed, 34 skipped, 12 deselected in 66.53s (0:01:06) ======

It seems that the captured output has 2 lines instead of one for some reason. I've tried to play around with COLUMNS env variable and it did not help.

The problem is that I'm not able to reproduce the problem outside of the Fedora build system (and mock).

The new version of pip vendors new versions of rich and colorama and my guess is that this problem might relate to that. See pypa/pip@22.3.1...23.0.1#diff-4054444a00305c03a81eff54cb76a5ec5d0001b8671420fa6760a172c8249f4d

Do you have an idea what might be causing this? I'm looking for an environment variable or some setting which stops the wrapping.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions