@@ -65,9 +65,11 @@ class TestFilesCollection:
6565 """
6666
6767 # the name for the collection of files
68- name : str
68+ name : str = "<unnamed test file collection>"
6969 # static or computed contents
70- contents : dict [str , str | typing .Callable [[pathlib .Path ], str ]]
70+ contents : dict [str , str | typing .Callable [[pathlib .Path ], str ]] = dataclasses .field (
71+ default_factory = dict
72+ )
7173
7274 def __str__ (self ) -> str :
7375 return self .name
@@ -4047,6 +4049,50 @@ def test_second_order_requirements_relative_path_in_separate_dir(
40474049 )
40484050
40494051
4052+ def test_second_order_requirements_can_be_in_parent_of_cwd (
4053+ pip_conf ,
4054+ runner ,
4055+ tmp_path ,
4056+ monkeypatch ,
4057+ pip_produces_absolute_paths ,
4058+ ):
4059+ """
4060+ Test handling of ``-r`` includes when the included requirements file is in the
4061+ parent of the current working directory.
4062+ """
4063+ test_files_collection = TestFilesCollection (
4064+ contents = {
4065+ "subdir1/requirements.in" : "-r ../requirements2.in\n " ,
4066+ "requirements2.in" : "small-fake-a\n " ,
4067+ }
4068+ )
4069+ test_files_collection .populate (tmp_path )
4070+
4071+ with monkeypatch .context () as revertable_ctx :
4072+ # cd into the subdir where the initial requirements are
4073+ revertable_ctx .chdir (tmp_path / "subdir1" )
4074+ out = runner .invoke (
4075+ cli ,
4076+ [
4077+ "--output-file" ,
4078+ "-" ,
4079+ "--quiet" ,
4080+ "--no-header" ,
4081+ "--no-emit-options" ,
4082+ "-r" ,
4083+ "requirements.in" ,
4084+ ],
4085+ )
4086+
4087+ assert out .exit_code == 0
4088+ assert out .stdout == dedent (
4089+ """\
4090+ small-fake-a==0.2
4091+ # via -r ../requirements2.in
4092+ """
4093+ )
4094+
4095+
40504096@pytest .mark .parametrize (
40514097 "input_path_absolute" , (True , False ), ids = ("absolute-input" , "relative-input" )
40524098)
0 commit comments