From 3e943d9e79675e71d29d473f98ba4a6c582ab983 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Mon, 28 Aug 2023 07:33:42 +0300 Subject: [PATCH] Resolve all paths in the include directive (#11650) Because pytest's base tmp_path is also in /tmp, ``source`` here is relative path, and thus is not properly converted to doc name. So the test fails because `sources_reported` dict has a key like ``../../../pytest/pytest-0/directive-include/baz/baz``, and ``assert "baz/baz" in sources_reported`` fails. Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com> --- sphinx/directives/other.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py index 8caef4f05fb..20fb05b5048 100644 --- a/sphinx/directives/other.py +++ b/sphinx/directives/other.py @@ -1,6 +1,7 @@ from __future__ import annotations import re +from os.path import abspath from typing import TYPE_CHECKING, Any, cast from docutils import nodes @@ -386,7 +387,7 @@ def _insert_input(include_lines, source): text = "\n".join(include_lines[:-2]) # The docname to pass into the source-read event - docname = self.env.path2doc(os_path(source)) + docname = self.env.path2doc(abspath(os_path(source))) # Emit the "source-read" event arg = [text] self.env.app.events.emit("source-read", docname, arg)