diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php
index 6d5c91d70e232..e124e2dd7ade1 100644
--- a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php
+++ b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php
@@ -159,7 +159,10 @@ public static function build_html5_treelike_string( $fragment_context, $html ) {
$indent_level = $tag_indent + 1;
}
- $output .= str_repeat( $indent, $tag_indent ) . "<{$tag_name}>\n";
+ $namespace = $processor->get_namespace();
+ $namespace = $namespace === 'html' ? '' : "{$namespace} ";
+
+ $output .= str_repeat( $indent, $tag_indent ) . "<{$namespace}{$tag_name}>\n";
$attribute_names = $processor->get_attribute_names_with_prefix( '' );
if ( $attribute_names ) {