@@ -378,7 +378,7 @@ def __init__(self, base_path, *args, **kwargs):
378
378
379
379
# Whether all pip invocations should expect stderr
380
380
# (useful for Python version deprecation)
381
- self .pip_expect_stderr = kwargs .pop ('pip_expect_stderr ' , None )
381
+ self .pip_expect_warning = kwargs .pop ('pip_expect_warning ' , None )
382
382
383
383
# Call the TestFileEnvironment __init__
384
384
super (PipTestEnvironment , self ).__init__ (base_path , * args , ** kwargs )
@@ -423,9 +423,9 @@ def run(self, *args, **kw):
423
423
:param allow_stderr_error: whether a logged error is allowed in
424
424
stderr. Passing True for this argument implies
425
425
`allow_stderr_warning` since warnings are weaker than errors.
426
- :param expect_stderr: allow any stderr (equivalent to passing
427
- `allow_stderr_error `). This argument is an abbreviated version
428
- of `allow_stderr_error ` and is also kept for backwards
426
+ :param expect_stderr: whether to allow warnings in stderr (equivalent
427
+ to `allow_stderr_warning `). This argument is an abbreviated
428
+ version of `allow_stderr_warning ` and is also kept for backwards
429
429
compatibility.
430
430
"""
431
431
if self .verbose :
@@ -443,9 +443,22 @@ def run(self, *args, **kw):
443
443
allow_stderr_error = kw .pop ('allow_stderr_error' , None )
444
444
allow_stderr_warning = kw .pop ('allow_stderr_warning' , None )
445
445
446
- if kw .get ('expect_error' ) or kw . get ( 'expect_stderr' ) :
446
+ if kw .get ('expect_error' ):
447
447
# Then default to allowing logged errors.
448
+ if allow_stderr_error is not None and not allow_stderr_error :
449
+ raise RuntimeError (
450
+ 'cannot pass allow_stderr_error=False with '
451
+ 'expect_error=True'
452
+ )
448
453
allow_stderr_error = True
454
+ elif kw .get ('expect_stderr' ):
455
+ # Then default to allowing logged warnings.
456
+ if allow_stderr_warning is not None and not allow_stderr_warning :
457
+ raise RuntimeError (
458
+ 'cannot pass allow_stderr_warning=False with '
459
+ 'expect_stderr=True'
460
+ )
461
+ allow_stderr_warning = True
449
462
450
463
# Pass expect_stderr=True to allow any stderr. We do this because
451
464
# we do our checking of stderr further on in check_stderr().
@@ -460,14 +473,8 @@ def run(self, *args, **kw):
460
473
return TestPipResult (result , verbose = self .verbose )
461
474
462
475
def pip (self , * args , ** kwargs ):
463
- if self .pip_expect_stderr :
464
- kwargs ['expect_stderr' ] = True
465
- # On old versions of Python, urllib3/requests will raise a warning
466
- # about the lack of an SSLContext. Expect it when running commands
467
- # that will touch the outside world.
468
- if (pyversion_tuple < (2 , 7 , 9 ) and
469
- args and args [0 ] in ('search' , 'install' , 'download' )):
470
- kwargs ['expect_stderr' ] = True
476
+ if self .pip_expect_warning :
477
+ kwargs ['allow_stderr_warning' ] = True
471
478
if kwargs .pop ('use_module' , True ):
472
479
exe = 'python'
473
480
args = ('-m' , 'pip' ) + args
0 commit comments