code: def test_complex_custom_formatting():
      class User:
          def __init__(self, id, username):
              self.id = id
              self.username = username
  
          def __html_format__(self, format_spec):
              if format_spec == "link":
                  return Markup('<a href="/user/{0}">{1}</a>').format(
                      self.id, self.__html__()
                  )
              elif format_spec:
                  raise ValueError("Invalid format spec")
  
              return self.__html__()
  
          def __html__(self):
              return Markup("<span class=user>{0}</span>").format(
                  self.username
              )
  
      user = User(1, "foo")
      result = Markup("<p>User: {0:link}").format(user)
      expect = Markup(
          '<p>User: <a href="/user/1"><span class=user>foo</span></a>'
      )
      assert result == expect
  
imports: import pytest
  from markupsafe import Markup
label_desc: Use image node_id 14 for calling a global function with example usage: test_complex_custom_formatting() and returns: self, Markup, Markup