@@ -37,6 +37,7 @@ def test_creation() -> None:
3737 (None , "CID1<_FakeComponent>" ),
3838 ("test-component" , "CID1<_FakeComponent>:test-component" ),
3939 ],
40+ ids = ["no-name" , "with-name" ],
4041)
4142def test_str (name : str | None , expected_str : str ) -> None :
4243 """Test string representation of a component."""
@@ -114,8 +115,8 @@ def test_default_values() -> None:
114115 assert component .category_specific_metadata == {}
115116
116117
117- @pytest .mark .parametrize ("status" , list (ComponentStatus ))
118- @pytest .mark .parametrize ("lifetime_active" , [True , False ])
118+ @pytest .mark .parametrize ("status" , list (ComponentStatus ), ids = lambda s : s . name )
119+ @pytest .mark .parametrize ("lifetime_active" , [True , False ], ids = [ "active" , "inactive" ] )
119120def test_active_at (
120121 status : ComponentStatus , lifetime_active : bool , caplog : pytest .LogCaptureFixture
121122) -> None :
@@ -252,28 +253,19 @@ def test_active() -> None:
252253 category_specific_metadata = COMPONENT .category_specific_metadata ,
253254)
254255
255- ALL_COMPONENTS = [
256- COMPONENT ,
257- DIFFERENT_NONHASHABLE ,
258- DIFFERENT_STATUS ,
259- DIFFERENT_NAME ,
260- DIFFERENT_ID ,
261- DIFFERENT_MICROGRID_ID ,
262- DIFFERENT_BOTH_ID ,
263- ]
264-
265256
266257@pytest .mark .parametrize (
267258 "comp,expected" ,
268259 [
269- (COMPONENT , True ),
270- (DIFFERENT_NONHASHABLE , False ),
271- (DIFFERENT_STATUS , False ),
272- (DIFFERENT_NAME , False ),
273- (DIFFERENT_ID , False ),
274- (DIFFERENT_MICROGRID_ID , False ),
275- (DIFFERENT_BOTH_ID , False ),
260+ pytest . param (COMPONENT , True , id = "self" ),
261+ pytest . param (DIFFERENT_NONHASHABLE , False , id = "other-nonhashable" ),
262+ pytest . param (DIFFERENT_STATUS , False , id = "other-status" ),
263+ pytest . param (DIFFERENT_NAME , False , id = "other-name" ),
264+ pytest . param (DIFFERENT_ID , False , id = "other-id" ),
265+ pytest . param (DIFFERENT_MICROGRID_ID , False , id = "other-microgrid-id" ),
266+ pytest . param (DIFFERENT_BOTH_ID , False , id = "other-both-ids" ),
276267 ],
268+ ids = lambda o : str (o .id ) if isinstance (o , Component ) else str (o ),
277269)
278270def test_equality (comp : Component , expected : bool ) -> None :
279271 """Test component equality."""
@@ -286,13 +278,13 @@ def test_equality(comp: Component, expected: bool) -> None:
286278@pytest .mark .parametrize (
287279 "comp,expected" ,
288280 [
289- (COMPONENT , True ),
290- (DIFFERENT_NONHASHABLE , True ),
291- (DIFFERENT_STATUS , True ),
292- (DIFFERENT_NAME , True ),
293- (DIFFERENT_ID , False ),
294- (DIFFERENT_MICROGRID_ID , False ),
295- (DIFFERENT_BOTH_ID , False ),
281+ pytest . param (COMPONENT , True , id = "self" ),
282+ pytest . param (DIFFERENT_NONHASHABLE , True , id = "other-nonhashable" ),
283+ pytest . param (DIFFERENT_STATUS , True , id = "other-status" ),
284+ pytest . param (DIFFERENT_NAME , True , id = "other-name" ),
285+ pytest . param (DIFFERENT_ID , False , id = "other-id" ),
286+ pytest . param (DIFFERENT_MICROGRID_ID , False , id = "other-microgrid-id" ),
287+ pytest . param (DIFFERENT_BOTH_ID , False , id = "other-both-ids" ),
296288 ],
297289)
298290def test_identity (comp : Component , expected : bool ) -> None :
@@ -301,8 +293,19 @@ def test_identity(comp: Component, expected: bool) -> None:
301293 assert comp .identity == (comp .id , comp .microgrid_id )
302294
303295
304- @pytest .mark .parametrize ("comp1" , ALL_COMPONENTS )
305- @pytest .mark .parametrize ("comp2" , ALL_COMPONENTS )
296+ ALL_COMPONENTS_PARAMS = [
297+ pytest .param (COMPONENT , id = "comp" ),
298+ pytest .param (DIFFERENT_NONHASHABLE , id = "nonhashable" ),
299+ pytest .param (DIFFERENT_STATUS , id = "status" ),
300+ pytest .param (DIFFERENT_NAME , id = "name" ),
301+ pytest .param (DIFFERENT_ID , id = "id" ),
302+ pytest .param (DIFFERENT_MICROGRID_ID , id = "microgrid_id" ),
303+ pytest .param (DIFFERENT_BOTH_ID , id = "both_ids" ),
304+ ]
305+
306+
307+ @pytest .mark .parametrize ("comp1" , ALL_COMPONENTS_PARAMS )
308+ @pytest .mark .parametrize ("comp2" , ALL_COMPONENTS_PARAMS )
306309def test_hash (comp1 : Component , comp2 : Component ) -> None :
307310 """Test that the hash is consistent."""
308311 # We can only say the hash are the same if the components are equal, if they
0 commit comments