From f4f0c76a3c0f279302b8a7605f33d5619ba2b25b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 26 Nov 2025 11:23:46 +0000 Subject: [PATCH 1/2] Initial plan From 10cfee39d515e7755f82b7ee377a2f57859ecbf4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 26 Nov 2025 11:33:28 +0000 Subject: [PATCH 2/2] Add test case for MkDocs missing config file error Co-authored-by: humitos <244656+humitos@users.noreply.github.com> --- .../rtd_tests/tests/test_doc_builder.py | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/readthedocs/rtd_tests/tests/test_doc_builder.py b/readthedocs/rtd_tests/tests/test_doc_builder.py index e510de3a45a..605d8c66d71 100644 --- a/readthedocs/rtd_tests/tests/test_doc_builder.py +++ b/readthedocs/rtd_tests/tests/test_doc_builder.py @@ -8,9 +8,11 @@ from django.test.utils import override_settings from readthedocs.config.tests.test_config import get_build_config +from readthedocs.doc_builder.backends.mkdocs import BaseMkdocs from readthedocs.doc_builder.backends.sphinx import BaseSphinx from readthedocs.doc_builder.python_environments import Virtualenv from readthedocs.projects.exceptions import ProjectConfigurationError +from readthedocs.projects.exceptions import UserFileNotFound from readthedocs.projects.models import Project @@ -112,3 +114,62 @@ def test_multiple_conf_py( with pytest.raises(ProjectConfigurationError): with override_settings(DOCROOT=tmp_docs_dir): base_sphinx.show_conf() + + +@override_settings(PRODUCTION_DOMAIN="readthedocs.org") +class MkDocsBuilderTest(TestCase): + fixtures = ["test_data", "eric"] + + def setUp(self): + self.project = Project.objects.get(slug="pip") + self.version = self.project.versions.first() + + self.build_env = mock.MagicMock() + self.build_env.project = self.project + self.build_env.version = self.version + self.build_env.build = { + "id": 123, + } + self.build_env.api_client = mock.MagicMock() + + @patch("readthedocs.doc_builder.backends.mkdocs.BaseMkdocs.run") + @patch("readthedocs.projects.models.Project.checkout_path") + @patch("readthedocs.doc_builder.python_environments.load_yaml_config") + def test_project_without_mkdocs_yml( + self, + load_yaml_config, + checkout_path, + _, + ): + """ + Test for a project with a missing ``mkdocs.yml`` file. + + When ``mkdocs.configuration`` points to a file that doesn't exist, + a ``UserFileNotFound`` error should be raised. + """ + tmp_dir = tempfile.mkdtemp() + checkout_path.return_value = tmp_dir + python_env = Virtualenv( + version=self.version, + build_env=self.build_env, + config=get_build_config( + {"mkdocs": {"configuration": "mkdocs.yml"}}, + validate=True, + source_file=f"{tmp_dir}/readthedocs.yml", + ), + ) + base_mkdocs = BaseMkdocs( + build_env=self.build_env, + python_env=python_env, + ) + with self.assertRaises(UserFileNotFound) as e: + base_mkdocs.show_conf() + + self.assertEqual( + e.exception.message_id, + UserFileNotFound.FILE_NOT_FOUND, + ) + self.assertEqual( + e.exception.format_values.get("filename"), + "mkdocs.yml", + )