@@ -295,7 +295,8 @@ def test_section_twice():
295295-----
296296That should break...
297297"""
298- assert_raises (ValueError , NumpyDocString , doc_text )
298+ with pytest .raises (ValueError , match = "The section Notes appears twice" ):
299+ NumpyDocString (doc_text )
299300
300301 # if we have a numpydoc object, we know where the error came from
301302 class Dummy :
@@ -332,19 +333,11 @@ def dummy_func(arg):
332333 Second note.
333334 """
334335
335- try :
336+ with pytest . raises ( ValueError , match = "Dummy class" ) :
336337 SphinxClassDoc (Dummy )
337- except ValueError as e :
338- # python 3 version or python 2 version
339- assert ("test_section_twice.<locals>.Dummy" in str (e )
340- or 'test_docscrape.Dummy' in str (e ))
341338
342- try :
339+ with pytest . raises ( ValueError , match = "dummy_func" ) :
343340 SphinxFunctionDoc (dummy_func )
344- except ValueError as e :
345- # python 3 version or python 2 version
346- assert ("test_section_twice.<locals>.dummy_func" in str (e )
347- or 'function dummy_func' in str (e ))
348341
349342
350343def test_notes (doc ):
@@ -842,13 +835,9 @@ def test_see_also_parse_error():
842835 --------
843836 :func:`~foo`
844837 """ )
845- with assert_raises ( ParseError ) as err :
838+ with pytest . raises ( ValueError , match = "See Also entry ':func:`~foo`'" ) :
846839 NumpyDocString (text )
847840
848- s1 = str (r":func:`~foo` is not a item name in '\n z(x,theta)\n\n See Also\n --------\n :func:`~foo`\n '" )
849- s2 = str (err .value )
850- assert s1 == s2
851-
852841
853842def test_see_also_print ():
854843 class Dummy :
@@ -901,19 +890,16 @@ class BadSection:
901890 """
902891 pass
903892
904- with warnings .catch_warnings (record = True ) as w :
905- warnings .filterwarnings ('always' , '' , UserWarning )
893+ with pytest .warns (UserWarning , match = "Unknown section Mope" ) as record :
906894 NumpyDocString (doc_text )
907- assert len (w ) == 1
908- assert "Unknown section Mope" == str (w [0 ].message )
895+ assert len (record ) == 1
909896
910- with warnings .catch_warnings (record = True ) as w :
911- warnings .filterwarnings ('always' , '' , UserWarning )
897+ # SphinxClassDoc has _obj.__name__ == "BadSection". Test that this is
898+ # included in the message
899+ msg_match = "Unknown section Nope in the docstring of BadSection"
900+ with pytest .warns (UserWarning , match = msg_match ) as record :
912901 SphinxClassDoc (BadSection )
913- assert len (w ) == 1
914- assert ('test_docscrape.test_unknown_section.<locals>.BadSection'
915- in str (w [0 ].message )
916- or 'test_docscrape.BadSection' in str (w [0 ].message ))
902+ assert len (record ) == 1
917903
918904
919905doc7 = NumpyDocString ("""
0 commit comments