def test_doc_to_json_underscore_error_serialize(doc):
    """Test that Doc.to_json() raises an error if a custom attribute value
    isn't JSON-serializable."""
    Doc.set_extension("json_test4", method=lambda doc: doc.text)
    with pytest.raises(ValueError):
        doc.to_json(underscore=["json_test4"])
Test that Doc.to_json() raises an error if a custom attribute value
    isn't JSON-serializable.
spacy/tests/doc/test_json_doc_conversion.py