From 9110968dfce05a4d69a7f794a77d135a7bf33c16 Mon Sep 17 00:00:00 2001 From: ftnext Date: Mon, 5 Aug 2024 23:13:37 +0900 Subject: [PATCH] [refactor] Pass directory name with pytest's fixture --- pyproject.toml | 3 +++ tests/test_show_external_link_icon.py | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 739a8ce..7a2e6fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,3 +55,6 @@ format_isort = "isort --profile black -l 79 src tests setup.py" check = "task check_flake8 && task check_mypy" check_flake8 = "flake8 src tests" check_mypy = "mypy src tests" + +[tool.pytest.ini_options] +markers = ["sphinx_build_in_tempdir"] diff --git a/tests/test_show_external_link_icon.py b/tests/test_show_external_link_icon.py index fda1e67..5e60f72 100644 --- a/tests/test_show_external_link_icon.py +++ b/tests/test_show_external_link_icon.py @@ -7,13 +7,19 @@ @pytest.fixture def parsed_built_html( + request, make_app, sphinx_test_tempdir: Path, rootdir: Path, ): - srcdir = sphinx_test_tempdir / "external-link-icon" + marker = request.node.get_closest_marker("sphinx_build_in_tempdir") + if marker is None: + raise RuntimeError("Mark as `sphinx_build_in_tempdir`") + directory_name = marker.args[0] + + srcdir = sphinx_test_tempdir / directory_name if not srcdir.exists(): - testroot_path = rootdir / "test-external-link-icon" + testroot_path = rootdir / f"test-{directory_name}" shutil.copytree(testroot_path, srcdir) app = make_app("html", srcdir=srcdir) @@ -29,6 +35,7 @@ def assert_is_external(reference, expected_url: str) -> None: assert reference["rel"] == ["noopener", "noreferrer"] +@pytest.mark.sphinx_build_in_tempdir("external-link-icon") def test_see_external_link_icon(parsed_built_html): references = parsed_built_html.find_all("a", {"class": "reference"}) @@ -38,6 +45,7 @@ def test_see_external_link_icon(parsed_built_html): assert_is_external(ref, "https://pypi.org/project/sphinx-new-tab-link/") +@pytest.mark.sphinx_build_in_tempdir("external-link-icon") def test_can_see_icon_with_image_directive_target(parsed_built_html): # https://github.com/ftnext/sphinx-new-tab-link/issues/16 references = parsed_built_html.find_all("a", {"class": "reference"}) @@ -52,6 +60,7 @@ def test_can_see_icon_with_image_directive_target(parsed_built_html): assert ref.svg +@pytest.mark.sphinx_build_in_tempdir("external-link-icon") def test_can_see_icon_with_figure_directive_target(parsed_built_html): references = parsed_built_html.find_all("a", {"class": "reference"})