code: def _doctree_for_test(builder, docname: str) -> nodes.document:
      builder.env.prepare_settings(docname)
      publisher = create_publisher(builder.app, "restructuredtext")
      with sphinx_domains(builder.env):
          publisher.set_source(
              source_path=builder.env.doc2path(docname)
          )
          publisher.publish()
          return publisher.document
  
file_path: sphinx/tests/test_directives/test_directive_object_description.py
imports: import docutils.utils
  import pytest
  from docutils import nodes
  from sphinx import addnodes
  from sphinx.io import create_publisher
  from sphinx.testing import restructuredtext
  from sphinx.util.docutils import sphinx_domains
label_desc: Use image node_id 1 for calling a global function with example usage: _doctree_for_test(builder, docname) and returns: publisher