From 00e0d81ecc1c308528e22e42f649a456576e8aaf Mon Sep 17 00:00:00 2001 From: Karolina Surma Date: Mon, 19 Jan 2026 12:09:32 +0100 Subject: [PATCH 1/2] Unify the conftest imports and set the import mode to discover them The tests have two ways of importing from conftest: directly and via tests.conftest. When running the tests directly via `pytest`, the output is: ___________________ ERROR collecting tests/test_html/test_html_to_nodes.py ____________________ ImportError while importing test module '/builddir/build/BUILD/python-myst-parser-5.0.0-build/MyST-Parser-5.0.0/tests/test_html/test_html_to_nodes.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib64/python3.14/importlib/__init__.py:88: in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tests/test_html/test_html_to_nodes.py:9: in from tests.conftest import normalize_doctree_xml E ModuleNotFoundError: No module named 'tests' When running with `pytest --import-mode=importlib`, other tests raise ImportError: _______________ ERROR collecting tests/test_renderers/test_fixtures_docutils.py _______________ ImportError while importing test module '/builddir/build/BUILD/python-myst-parser-5.0.0-build/MyST-Parser-5.0.0/tests/test_renderers/test_fixtures_docutils.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: tests/test_renderers/test_fixtures_docutils.py:14: in from conftest import normalize_doctree_xml E ModuleNotFoundError: No module named 'conftest' It's not possible to fix everything so that the direct imports from conftest are applied, because there are two conftest.py files present in the repository at different locations. The fix applied imports from `tests.conftest` everywhere, which also requires a change in the import mode, added to pyproject.toml. The end result works consistently when invoked just with `pytest`. --- pyproject.toml | 1 + tests/test_renderers/test_fixtures_docutils.py | 2 +- tests/test_renderers/test_include_directive.py | 2 +- tests/test_renderers/test_myst_config.py | 2 +- tests/test_renderers/test_myst_refs.py | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1f9440f9..ebfb8377 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -148,6 +148,7 @@ filterwarnings = [ "ignore:.*The default for the setting.*:FutureWarning", "ignore:.*:PendingDeprecationWarning", ] +addopts = "--import-mode=importlib" [tool.coverage.run] omit = ["*/_docs.py"] diff --git a/tests/test_renderers/test_fixtures_docutils.py b/tests/test_renderers/test_fixtures_docutils.py index c46e51c7..e839a0d7 100644 --- a/tests/test_renderers/test_fixtures_docutils.py +++ b/tests/test_renderers/test_fixtures_docutils.py @@ -11,7 +11,7 @@ from typing import Any import pytest -from conftest import normalize_doctree_xml +from tests.conftest import normalize_doctree_xml from docutils import __version_info__ as docutils_version from docutils.core import Publisher, publish_doctree from pytest_param_files import ParamTestData diff --git a/tests/test_renderers/test_include_directive.py b/tests/test_renderers/test_include_directive.py index e7065747..d708e39d 100644 --- a/tests/test_renderers/test_include_directive.py +++ b/tests/test_renderers/test_include_directive.py @@ -3,7 +3,7 @@ from pathlib import Path import pytest -from conftest import normalize_doctree_xml +from tests.conftest import normalize_doctree_xml from docutils.core import publish_doctree from myst_parser.parsers.docutils_ import Parser diff --git a/tests/test_renderers/test_myst_config.py b/tests/test_renderers/test_myst_config.py index 9a276cce..02992ea5 100644 --- a/tests/test_renderers/test_myst_config.py +++ b/tests/test_renderers/test_myst_config.py @@ -5,7 +5,7 @@ from pathlib import Path import pytest -from conftest import normalize_doctree_xml +from tests.conftest import normalize_doctree_xml from docutils import __version_info__ as docutils_version from docutils.core import Publisher, publish_string from pytest_param_files import ParamTestData diff --git a/tests/test_renderers/test_myst_refs.py b/tests/test_renderers/test_myst_refs.py index fcdfd619..92ff098d 100644 --- a/tests/test_renderers/test_myst_refs.py +++ b/tests/test_renderers/test_myst_refs.py @@ -1,7 +1,7 @@ import sys import pytest -from conftest import normalize_doctree_xml +from tests.conftest import normalize_doctree_xml from sphinx.util.console import strip_colors from sphinx_pytest.plugin import CreateDoctree From bb21809576322c1b6ade12823c90897daaf02162 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 19 Jan 2026 11:50:19 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_renderers/test_fixtures_docutils.py | 2 +- tests/test_renderers/test_include_directive.py | 2 +- tests/test_renderers/test_myst_config.py | 2 +- tests/test_renderers/test_myst_refs.py | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_renderers/test_fixtures_docutils.py b/tests/test_renderers/test_fixtures_docutils.py index e839a0d7..37954792 100644 --- a/tests/test_renderers/test_fixtures_docutils.py +++ b/tests/test_renderers/test_fixtures_docutils.py @@ -11,12 +11,12 @@ from typing import Any import pytest -from tests.conftest import normalize_doctree_xml from docutils import __version_info__ as docutils_version from docutils.core import Publisher, publish_doctree from pytest_param_files import ParamTestData from myst_parser.parsers.docutils_ import Parser +from tests.conftest import normalize_doctree_xml FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures") diff --git a/tests/test_renderers/test_include_directive.py b/tests/test_renderers/test_include_directive.py index d708e39d..430b967b 100644 --- a/tests/test_renderers/test_include_directive.py +++ b/tests/test_renderers/test_include_directive.py @@ -3,10 +3,10 @@ from pathlib import Path import pytest -from tests.conftest import normalize_doctree_xml from docutils.core import publish_doctree from myst_parser.parsers.docutils_ import Parser +from tests.conftest import normalize_doctree_xml FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures") diff --git a/tests/test_renderers/test_myst_config.py b/tests/test_renderers/test_myst_config.py index 02992ea5..7833c1e1 100644 --- a/tests/test_renderers/test_myst_config.py +++ b/tests/test_renderers/test_myst_config.py @@ -5,12 +5,12 @@ from pathlib import Path import pytest -from tests.conftest import normalize_doctree_xml from docutils import __version_info__ as docutils_version from docutils.core import Publisher, publish_string from pytest_param_files import ParamTestData from myst_parser.parsers.docutils_ import Parser +from tests.conftest import normalize_doctree_xml FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures") INV_PATH = Path(__file__).parent.parent.absolute() / "static" / "objects_v2.inv" diff --git a/tests/test_renderers/test_myst_refs.py b/tests/test_renderers/test_myst_refs.py index 92ff098d..af8757be 100644 --- a/tests/test_renderers/test_myst_refs.py +++ b/tests/test_renderers/test_myst_refs.py @@ -1,10 +1,11 @@ import sys import pytest -from tests.conftest import normalize_doctree_xml from sphinx.util.console import strip_colors from sphinx_pytest.plugin import CreateDoctree +from tests.conftest import normalize_doctree_xml + @pytest.mark.parametrize( "test_name,text,should_warn",