@@ -770,11 +770,16 @@ def test_install_req_drop_extras(self, inp: str, out: str) -> None:
770
770
without_extras = install_req_drop_extras (req )
771
771
assert not without_extras .extras
772
772
assert str (without_extras .req ) == out
773
- # should always be a copy
774
- assert req is not without_extras
775
- assert req .req is not without_extras .req
773
+
774
+ # if there are no extras they should be the same object,
775
+ # otherwise they may be a copy due to cache
776
+ if req .extras :
777
+ assert req is not without_extras
778
+ assert req .req is not without_extras .req
779
+
776
780
# comes_from should point to original
777
781
assert without_extras .comes_from is req
782
+
778
783
# all else should be the same
779
784
assert without_extras .link == req .link
780
785
assert without_extras .markers == req .markers
@@ -790,9 +795,9 @@ def test_install_req_drop_extras(self, inp: str, out: str) -> None:
790
795
@pytest .mark .parametrize (
791
796
"inp, extras, out" ,
792
797
[
793
- ("pkg" , {} , "pkg" ),
794
- ("pkg==1.0" , {} , "pkg==1.0" ),
795
- ("pkg[ext]" , {} , "pkg[ext]" ),
798
+ ("pkg" , set () , "pkg" ),
799
+ ("pkg==1.0" , set () , "pkg==1.0" ),
800
+ ("pkg[ext]" , set () , "pkg[ext]" ),
796
801
("pkg" , {"ext" }, "pkg[ext]" ),
797
802
("pkg==1.0" , {"ext" }, "pkg[ext]==1.0" ),
798
803
("pkg==1.0" , {"ext1" , "ext2" }, "pkg[ext1,ext2]==1.0" ),
@@ -816,9 +821,14 @@ def test_install_req_extend_extras(
816
821
assert str (extended .req ) == out
817
822
assert extended .req is not None
818
823
assert set (extended .extras ) == set (extended .req .extras )
819
- # should always be a copy
820
- assert req is not extended
821
- assert req .req is not extended .req
824
+
825
+ # if extras is not a subset of req.extras then the extended
826
+ # requirement object should not be the same, otherwise they
827
+ # might be a copy due to cache
828
+ if not extras .issubset (req .extras ):
829
+ assert req is not extended
830
+ assert req .req is not extended .req
831
+
822
832
# all else should be the same
823
833
assert extended .link == req .link
824
834
assert extended .markers == req .markers
0 commit comments