Skip to content

Commit 3dd5eaf

Browse files
committed
Refactor tests to share functionability
1 parent 3338093 commit 3dd5eaf

File tree

4 files changed

+44
-38
lines changed

4 files changed

+44
-38
lines changed

tests/__init__.py

Whitespace-only changes.

tests/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
import shutil
3+
import pytest
4+
5+
from .utils import srcdir, prefixdocumentsrcdir, customobjectsrcdir, pythondomainsrcdir
6+
7+
8+
@pytest.fixture(autouse=True, scope='function')
9+
def remove_sphinx_build_output():
10+
"""Remove _build/ folder, if exist."""
11+
for path in (srcdir, prefixdocumentsrcdir, customobjectsrcdir, pythondomainsrcdir):
12+
build_path = os.path.join(path, '_build')
13+
if os.path.exists(build_path):
14+
shutil.rmtree(build_path)

tests/test_htmltag.py

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,6 @@
1-
import os
21
import pytest
3-
import shutil
42

5-
6-
srcdir = os.path.join(
7-
os.path.dirname(os.path.abspath(__file__)),
8-
'examples',
9-
'default',
10-
)
11-
12-
# srcdir with ``autosectionlabel_prefix_document = True`` config
13-
prefixdocumentsrcdir = os.path.join(
14-
os.path.dirname(os.path.abspath(__file__)),
15-
'examples',
16-
'prefixdocument',
17-
)
18-
19-
# srcdir with ``Sphinx.add_object_type`` call
20-
customobjectsrcdir = os.path.join(
21-
os.path.dirname(os.path.abspath(__file__)),
22-
'examples',
23-
'custom-object',
24-
)
25-
26-
# srcdir with ``:py:class:`` call
27-
pythondomainsrcdir = os.path.join(
28-
os.path.dirname(os.path.abspath(__file__)),
29-
'examples',
30-
'python-domain',
31-
)
32-
33-
34-
@pytest.fixture(autouse=True, scope='function')
35-
def remove_sphinx_build_output():
36-
"""Remove _build/ folder, if exist."""
37-
for path in (srcdir, prefixdocumentsrcdir, customobjectsrcdir, pythondomainsrcdir):
38-
build_path = os.path.join(path, '_build')
39-
if os.path.exists(build_path):
40-
shutil.rmtree(build_path)
3+
from .utils import srcdir, prefixdocumentsrcdir, customobjectsrcdir, pythondomainsrcdir
414

425

436
@pytest.mark.sphinx(

tests/utils.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
3+
4+
srcdir = os.path.join(
5+
os.path.dirname(os.path.abspath(__file__)),
6+
'examples',
7+
'default',
8+
)
9+
10+
# srcdir with ``autosectionlabel_prefix_document = True`` config
11+
prefixdocumentsrcdir = os.path.join(
12+
os.path.dirname(os.path.abspath(__file__)),
13+
'examples',
14+
'prefixdocument',
15+
)
16+
17+
# srcdir with ``Sphinx.add_object_type`` call
18+
customobjectsrcdir = os.path.join(
19+
os.path.dirname(os.path.abspath(__file__)),
20+
'examples',
21+
'custom-object',
22+
)
23+
24+
# srcdir with ``:py:class:`` call
25+
pythondomainsrcdir = os.path.join(
26+
os.path.dirname(os.path.abspath(__file__)),
27+
'examples',
28+
'python-domain',
29+
)

0 commit comments

Comments
 (0)