Skip to content

Commit b52fdbd

Browse files
henryiiiFFY00
authored andcommitted
tests: strip formatting from stderr (pip 23)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent e496fe6 commit b52fdbd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tests/test_main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
cwd = os.getcwd()
2121
out = os.path.join(cwd, 'dist')
2222

23+
ANSI_STRIP = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
24+
2325

2426
@pytest.mark.parametrize(
2527
('cli_args', 'build_args', 'hook'),
@@ -368,8 +370,10 @@ def test_output_env_subprocess_error(
368370
assert stdout[:4] == stdout_body
369371
assert stdout[-1].startswith(stdout_error)
370372

371-
assert len(stderr) == 1
372-
assert stderr[0].startswith('ERROR: Invalid requirement: ')
373+
# Newer versions of pip also color stderr - strip them if present
374+
cleaned_stderr = ANSI_STRIP.sub('', '\n'.join(stderr)).strip()
375+
assert len(cleaned_stderr.splitlines()) == 1
376+
assert cleaned_stderr.startswith('ERROR: Invalid requirement: ')
373377

374378

375379
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)