File tree Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change
1
+ Fix pip to work with warnings converted to errors.
Original file line number Diff line number Diff line change 1
1
import os
2
2
import sys
3
+ import warnings
3
4
4
5
# Remove '' and current working directory from the first entry
5
6
# of sys.path, if present to avoid using current directory
18
19
path = os .path .dirname (os .path .dirname (__file__ ))
19
20
sys .path .insert (0 , path )
20
21
21
- from pip ._internal .cli .main import main as _main
22
-
23
22
if __name__ == "__main__" :
23
+ # Work around the error reported in #9540, pending a proper fix.
24
+ # Note: It is essential the warning filter is set *before* importing
25
+ # pip, as the deprecation happens at import time, not runtime.
26
+ warnings .filterwarnings (
27
+ "ignore" , category = DeprecationWarning , module = ".*packaging\\ .version"
28
+ )
29
+ from pip ._internal .cli .main import main as _main
30
+
24
31
sys .exit (_main ())
Original file line number Diff line number Diff line change @@ -42,3 +42,8 @@ def test_version_warning_is_not_shown_if_python_version_is_not_2(script):
42
42
43
43
def test_flag_does_nothing_if_python_version_is_not_2 (script ):
44
44
script .pip ("list" , "--no-python-version-warning" )
45
+
46
+
47
+ def test_pip_works_with_warnings_as_errors (script ):
48
+ script .environ ['PYTHONWARNINGS' ] = 'error'
49
+ script .pip ("--version" )
You can’t perform that action at this time.
0 commit comments