Skip to content

Commit a5e91ee

Browse files
committed
[Doc] Fix broken pytest fixture
1 parent 66a304f commit a5e91ee

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

tests/conftest.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import nbformat as nbf
1616
import pytest
1717
import sphinx
18+
from sphinx.testing.path import path as sphinx_path
1819
from sphinx.util.console import nocolor
1920

2021
pytest_plugins = "sphinx.testing.fixtures"
@@ -148,7 +149,7 @@ def test_something(sphinx_run):
148149

149150

150151
@pytest.fixture()
151-
def sphinx_run(sphinx_params, make_app, tempdir):
152+
def sphinx_run(sphinx_params, make_app, tmpdir):
152153
"""A fixture to setup and run a sphinx build, in a sandboxed folder.
153154
154155
The `myst_nb` extension ius added by default,
@@ -169,11 +170,9 @@ def sphinx_run(sphinx_params, make_app, tempdir):
169170

170171
current_dir = os.getcwd()
171172
if "working_dir" in sphinx_params:
172-
from sphinx.testing.path import path
173-
174-
base_dir = path(sphinx_params["working_dir"]) / str(uuid.uuid4())
173+
base_dir = Path(sphinx_params["working_dir"]) / str(uuid.uuid4())
175174
else:
176-
base_dir = tempdir
175+
base_dir = Path(tmpdir)
177176
srcdir = base_dir / "source"
178177
srcdir.makedirs(exist_ok=True)
179178
os.chdir(base_dir)
@@ -188,11 +187,16 @@ def sphinx_run(sphinx_params, make_app, tempdir):
188187
for nb_file in sphinx_params["files"]:
189188
nb_path = TEST_FILE_DIR.joinpath(nb_file)
190189
assert nb_path.exists(), nb_path
191-
(srcdir / nb_file).parent.makedirs(exist_ok=True)
190+
(srcdir / nb_file).parent.mkdir(exist_ok=True)
192191
(srcdir / nb_file).write_text(nb_path.read_text(encoding="utf8"))
193192

194193
nocolor()
195-
app = make_app(buildername=buildername, srcdir=srcdir, confoverrides=confoverrides)
194+
195+
# For compatibility with multiple versions of sphinx, convert pathlib.Path to
196+
# sphinx.testing.path.path here.
197+
app = make_app(
198+
buildername=buildername, srcdir=sphinx_path(srcdir), confoverrides=confoverrides
199+
)
196200

197201
yield SphinxFixture(app, sphinx_params["files"])
198202

0 commit comments

Comments
 (0)