Skip to content

Commit ed2c8db

Browse files
committed
Fix tests
1 parent 3ccb656 commit ed2c8db

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tests/unit/test_req.py

+19-9
Original file line numberDiff line numberDiff line change
@@ -770,11 +770,16 @@ def test_install_req_drop_extras(self, inp: str, out: str) -> None:
770770
without_extras = install_req_drop_extras(req)
771771
assert not without_extras.extras
772772
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+
776780
# comes_from should point to original
777781
assert without_extras.comes_from is req
782+
778783
# all else should be the same
779784
assert without_extras.link == req.link
780785
assert without_extras.markers == req.markers
@@ -790,9 +795,9 @@ def test_install_req_drop_extras(self, inp: str, out: str) -> None:
790795
@pytest.mark.parametrize(
791796
"inp, extras, out",
792797
[
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]"),
796801
("pkg", {"ext"}, "pkg[ext]"),
797802
("pkg==1.0", {"ext"}, "pkg[ext]==1.0"),
798803
("pkg==1.0", {"ext1", "ext2"}, "pkg[ext1,ext2]==1.0"),
@@ -816,9 +821,14 @@ def test_install_req_extend_extras(
816821
assert str(extended.req) == out
817822
assert extended.req is not None
818823
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+
822832
# all else should be the same
823833
assert extended.link == req.link
824834
assert extended.markers == req.markers

0 commit comments

Comments
 (0)