File tree 3 files changed +18
-7
lines changed
3 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -75,13 +75,13 @@ def get_configuration_files():
75
75
for path in appdirs .site_config_dirs ('pip' )
76
76
]
77
77
78
- site_config_files = [
79
- os .path .join (sys .prefix , CONFIG_BASENAME )
80
- ]
78
+ site_config_files = []
81
79
if getattr (sys , 'base_prefix' , sys .prefix ) != sys .prefix :
82
80
site_config_files .append (
83
81
os .path .join (sys .base_prefix , CONFIG_BASENAME ),
84
82
)
83
+ # A virtual environment config takes precedence over a base_prefix config.
84
+ site_config_files .append (os .path .join (sys .prefix , CONFIG_BASENAME ))
85
85
86
86
legacy_config_file = os .path .join (
87
87
os .path .expanduser ('~' ),
Original file line number Diff line number Diff line change @@ -189,10 +189,11 @@ def test_site_modification(self):
189
189
190
190
self .configuration .set_value ("test.hello" , "10" )
191
191
192
- # get the path to site config file
192
+ # get the path to site config file, mirroring the behaviour
193
+ # in _get_parser_to_modify.
193
194
assert mymock .call_count == 1
194
195
assert mymock .call_args [0 ][0 ] == (
195
- get_configuration_files ()[kinds .SITE ][0 ]
196
+ get_configuration_files ()[kinds .SITE ][- 1 ]
196
197
)
197
198
198
199
def test_user_modification (self ):
Original file line number Diff line number Diff line change 1
1
import os
2
2
from contextlib import contextmanager
3
+ import sys
3
4
from tempfile import NamedTemporaryFile
4
5
5
6
import pytest
@@ -433,20 +434,29 @@ def test_client_cert(self):
433
434
434
435
class TestOptionsConfigFiles :
435
436
436
- def test_venv_config_file_found (self , monkeypatch ):
437
+ @pytest .mark .parametrize ("in_venv" , (True , False ))
438
+ def test_venv_config_file_found (self , monkeypatch , in_venv ):
437
439
# strict limit on the global config files list
438
440
monkeypatch .setattr (
439
441
pip ._internal .utils .appdirs , 'site_config_dirs' ,
440
442
lambda _ : ['/a/place' ]
441
443
)
444
+ if in_venv :
445
+ monkeypatch .setattr (sys , 'base_prefix' , '/some/other/place' )
446
+ else :
447
+ monkeypatch .setattr (sys , 'base_prefix' , sys .prefix )
442
448
443
449
cp = pip ._internal .configuration .Configuration (isolated = False )
444
450
445
451
files = []
446
452
for _ , val in cp .iter_config_files ():
447
453
files .extend (val )
448
454
449
- assert len (files ) == 4
455
+ if in_venv :
456
+ # With venvs we get the config from the base_prefix also.
457
+ assert len (files ) == 5
458
+ else :
459
+ assert len (files ) == 4
450
460
451
461
@pytest .mark .parametrize (
452
462
"args, expect" ,
You can’t perform that action at this time.
0 commit comments