@@ -140,13 +140,19 @@ def test_empty_bom(self) -> None:
140140 self .assertFalse (bom .external_references )
141141
142142 def test_root_component_only_bom (self ) -> None :
143- with warnings .catch_warnings ():
144- warnings .simplefilter ('error' , UserWarning ) # Turn UserWarnings into errors
145- try :
146- bom = Bom (metadata = BomMetaData (component = Component (name = 'test' , version = '1.2' )))
147- _ = JsonV1Dot6 (bom ).output_as_string ()
148- except UserWarning as e :
149- self .fail (f"A warning with 'warn' was issued: { e } " )
143+ with warnings .catch_warnings (record = True ) as w :
144+ warnings .simplefilter ('always' )
145+ bom = Bom (metadata = BomMetaData (component = Component (name = 'test' , version = '1.2' )))
146+ _ = JsonV1Dot6 (bom ).output_as_string ()
147+ self .assertEqual (len (w ), 0 )
148+
149+ def test_warning_missing_dependency (self ) -> None :
150+ with self .assertWarns (expected_warning = UserWarning ) as w :
151+ bom = Bom (metadata = BomMetaData (component = Component (name = 'root_component' , version = '1.2' )))
152+ bom .components .add (Component (name = 'test2' , version = '4.2' ))
153+ _ = JsonV1Dot6 (bom ).output_as_string ()
154+ self .assertEqual (len (w .warnings ), 1 )
155+ self .assertIn ('has no defined dependencies ' , str (w .warnings [0 ]))
150156
151157 def test_empty_bom_defined_serial (self ) -> None :
152158 serial_number = uuid4 ()
0 commit comments