2
2
Test specific for the --no-color option
3
3
"""
4
4
import os
5
+ import shutil
5
6
import subprocess
7
+ import sys
6
8
7
9
import pytest
8
10
9
- from tests .lib import PipTestEnvironment
11
+ from tests .lib import PipTestEnvironment , TestData
10
12
11
13
12
- def test_no_color (script : PipTestEnvironment ) -> None :
14
+ @pytest .mark .skipif (shutil .which ("script" ) is None , reason = "no 'script' executable" )
15
+ def test_no_color (script : PipTestEnvironment , data : TestData ) -> None :
13
16
"""Ensure colour output disabled when --no-color is passed."""
14
17
# Using 'script' in this test allows for transparently testing pip's output
15
18
# since pip is smart enough to disable colour output when piped, which is
@@ -19,12 +22,14 @@ def test_no_color(script: PipTestEnvironment) -> None:
19
22
# 'script' and well as the mere use of the same.
20
23
#
21
24
# This test will stay until someone has the time to rewrite it.
22
- command = (
23
- "script --flush --quiet --return /tmp/pip-test-no-color.txt "
24
- '--command "pip uninstall {} noSuchPackage"'
25
- )
25
+ package = str (data .src / "pep518_invalid_build_system" )
26
+ pip_command = f"pip install --no-index {{}} { package } "
27
+ if sys .platform == "darwin" :
28
+ command = f"script -q /tmp/pip-test-no-color.txt { pip_command } "
29
+ else :
30
+ command = f'script -q /tmp/pip-test-no-color.txt --command "{ pip_command } "'
26
31
27
- def get_run_output (option : str ) -> str :
32
+ def get_run_output (option : str = "" ) -> str :
28
33
cmd = command .format (option )
29
34
proc = subprocess .Popen (
30
35
cmd ,
@@ -33,8 +38,6 @@ def get_run_output(option: str) -> str:
33
38
stderr = subprocess .PIPE ,
34
39
)
35
40
proc .communicate ()
36
- if proc .returncode :
37
- pytest .skip ("Unable to capture output using script: " + cmd )
38
41
39
42
try :
40
43
with open ("/tmp/pip-test-no-color.txt" ) as output_file :
@@ -43,7 +46,5 @@ def get_run_output(option: str) -> str:
43
46
finally :
44
47
os .unlink ("/tmp/pip-test-no-color.txt" )
45
48
46
- assert "\x1b " in get_run_output (option = "" ), "Expected color in output"
47
- assert "\x1b " not in get_run_output (
48
- option = "--no-color"
49
- ), "Expected no color in output"
49
+ assert "\x1b [3" in get_run_output ("" ), "Expected color in output"
50
+ assert "\x1b [3" not in get_run_output ("--no-color" ), "Expected no color in output"
0 commit comments