Skip to content

Commit

Permalink
[refactor] Pass directory name with pytest's fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
ftnext committed Aug 5, 2024
1 parent 37a047f commit 9110968
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
13 changes: 11 additions & 2 deletions tests/test_show_external_link_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"})

Expand All @@ -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"})
Expand All @@ -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"})

Expand Down

0 comments on commit 9110968

Please sign in to comment.