diff --git a/CHANGES b/CHANGES index 1634cdbb3..1c3478e17 100644 --- a/CHANGES +++ b/CHANGES @@ -34,6 +34,8 @@ Bugs fixed Testing -------- +* #3458: Add ``sphinx.testing` (experimental) + Release 1.6 beta3 (released May 07, 2017) ========================================= diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 20a6de0bb..18e4c2a16 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -337,3 +337,28 @@ warnings with: * ``PYTHONWARNINGS= make html`` (Linux/Mac) * ``export PYTHONWARNINGS=`` and do ``make html`` (Linux/Mac) * ``set PYTHONWARNINGS=`` and do ``make html`` (Windows) + +Unit Testing +------------ + +Sphinx has been tested with pytest runner. Sphinx developers write unit tests +using pytest notation. Utility functions and pytest fixtures for testing are +provided in ``sphinx.testing``. If you are a developer of Sphinx extensions, +you can write unit tests with using pytest. At this time, ``sphinx.testing`` +will help your test implementation. + +How to use pytest fixtures that are provided by ``sphinx.teting``? +You can require ``'sphinx.testing.fixtures'`` in your test modules or +``conftest.py`` files like this:: + + pytest_plugins = 'sphinx.testing.fixtures' + +If you want to know more detailed usage, please refer to ``tests/conftest.py`` +and other ``test_*.py`` files under ``tests`` directory. + +.. note:: + + Prior to Sphinx - 1.5.2, Sphinx was running the test with nose. + +.. versionadded:: 1.6 + ``sphinx.testing`` as a experimental. diff --git a/sphinx/testing/__init__.py b/sphinx/testing/__init__.py new file mode 100644 index 000000000..e246be8c0 --- /dev/null +++ b/sphinx/testing/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +""" + sphinx.testing + ~~~~~~~~~~~~~~ + + Sphinx test utilities + + You can require sphinx.testing pytest fixtures in a test module or a conftest + file like this: + + pytest_plugins = 'sphinx.testing.fixtures' + + :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py new file mode 100644 index 000000000..624adc03a --- /dev/null +++ b/sphinx/testing/fixtures.py @@ -0,0 +1,231 @@ +# -*- coding: utf-8 -*- +""" + sphinx.testing.fixtures + ~~~~~~~~~~~~~~~~~~~~~~~ + + Sphinx test fixtures for pytest + + :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" +from __future__ import print_function + +import os +import subprocess +import sys +from collections import namedtuple +from tempfile import gettempdir + +import pytest +from six import StringIO, string_types + +from . import util + +if False: + from typing import Dict, Union # NOQA + + +@pytest.fixture(scope='session') +def rootdir(): + return None + + +@pytest.fixture +def app_params(request, test_params, shared_result, sphinx_test_tempdir, rootdir): + """ + parameters that is specified by 'pytest.mark.sphinx' for + sphinx.application.Sphinx initialization + """ + + # ##### process pytest.mark.sphinx + + markers = request.node.get_marker("sphinx") + pargs = {} + kwargs = {} # type: Dict[str, str] + + if markers is not None: + # to avoid stacking positional args + for info in reversed(list(markers)): + for i, a in enumerate(info.args): + pargs[i] = a + kwargs.update(info.kwargs) + + args = [pargs[i] for i in sorted(pargs.keys())] + + # ##### process pytest.mark.test_params + + if test_params['shared_result']: + if 'srcdir' in kwargs: + raise pytest.Exception('You can not spcify shared_result and ' + 'srcdir in same time.') + kwargs['srcdir'] = test_params['shared_result'] + restore = shared_result.restore(test_params['shared_result']) + kwargs.update(restore) + + # ##### prepare Application params + + testroot = kwargs.pop('testroot', 'root') + kwargs['srcdir'] = srcdir = sphinx_test_tempdir / kwargs.get('srcdir', testroot) + + # special support for sphinx/tests + if rootdir and not srcdir.exists(): + testroot_path = rootdir / ('test-' + testroot) + testroot_path.copytree(srcdir) + + return namedtuple('app_params', 'args,kwargs')(args, kwargs) # type: ignore + + +@pytest.fixture +def test_params(request): + """ + test parameters that is specified by 'pytest.mark.test_params' + + :param Union[str] shared_result: + If the value is provided, app._status and app._warning objects will be + shared in the parametrized test functions and/or test functions that + have same 'shared_result' value. + **NOTE**: You can not specify shared_result and srcdir in same time. + """ + env = request.node.get_marker('test_params') + kwargs = env.kwargs if env else {} + result = { + 'shared_result': None, + } + result.update(kwargs) + + if (result['shared_result'] and + not isinstance(result['shared_result'], string_types)): + raise pytest.Exception('You can only provide a string type of value ' + 'for "shared_result" ') + return result + + +@pytest.fixture(scope='function') +def app(test_params, app_params, make_app, shared_result): + """ + provides sphinx.application.Sphinx object + """ + args, kwargs = app_params + app_ = make_app(*args, **kwargs) + yield app_ + + print('# testroot:', kwargs.get('testroot', 'root')) + print('# builder:', app_.builder.name) + print('# srcdir:', app_.srcdir) + print('# outdir:', app_.outdir) + print('# status:', '\n' + app_._status.getvalue()) + print('# warning:', '\n' + app_._warning.getvalue()) + + if test_params['shared_result']: + shared_result.store(test_params['shared_result'], app_) + + +@pytest.fixture(scope='function') +def status(app): + """ + compat for testing with previous @with_app decorator + """ + return app._status + + +@pytest.fixture(scope='function') +def warning(app): + """ + compat for testing with previous @with_app decorator + """ + return app._warning + + +@pytest.fixture() +def make_app(test_params): + """ + provides make_app function to initialize SphinxTestApp instance. + if you want to initialize 'app' in your test function. please use this + instead of using SphinxTestApp class directory. + """ + apps = [] + syspath = sys.path[:] + + def make(*args, **kwargs): + status, warning = StringIO(), StringIO() + kwargs.setdefault('status', status) + kwargs.setdefault('warning', warning) + app_ = util.SphinxTestApp(*args, **kwargs) # type: Union[util.SphinxTestApp, util.SphinxTestAppWrapperForSkipBuilding] # NOQA + apps.append(app_) + if test_params['shared_result']: + app_ = util.SphinxTestAppWrapperForSkipBuilding(app_) + return app_ + yield make + + sys.path[:] = syspath + for app_ in apps: + app_.cleanup() + + +class SharedResult(object): + cache = {} # type: Dict[str, Dict[str, str]] + + def store(self, key, app_): + if key in self.cache: + return + data = { + 'status': app_._status.getvalue(), + 'warning': app_._warning.getvalue(), + } + self.cache[key] = data + + def restore(self, key): + if key not in self.cache: + return {} + data = self.cache[key] + return { + 'status': StringIO(data['status']), + 'warning': StringIO(data['warning']), + } + + +@pytest.fixture +def shared_result(): + return SharedResult() + + +@pytest.fixture(scope='module', autouse=True) +def _shared_result_cache(): + SharedResult.cache.clear() + + +@pytest.fixture +def if_graphviz_found(app): + """ + The test will be skipped when using 'if_graphviz_found' fixture and graphviz + dot command is not found. + """ + graphviz_dot = getattr(app.config, 'graphviz_dot', '') + try: + if graphviz_dot: + dot = subprocess.Popen([graphviz_dot, '-V'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) # show version + dot.communicate() + return + except OSError: # No such file or directory + pass + + pytest.skip('graphviz "dot" is not available') + + +@pytest.fixture(scope='session') +def sphinx_test_tempdir(): + """ + temporary directory that wrapped with `path` class. + """ + return util.path(os.environ.get('SPHINX_TEST_TEMPDIR', gettempdir())).abspath() + + +@pytest.fixture +def tempdir(tmpdir): + """ + temporary directory that wrapped with `path` class. + this fixture is for compat with old test implementation. + """ + return util.path(tmpdir) diff --git a/tests/path.py b/sphinx/testing/path.py old mode 100755 new mode 100644 similarity index 96% rename from tests/path.py rename to sphinx/testing/path.py index 26c2b1b21..634d61332 --- a/tests/path.py +++ b/sphinx/testing/path.py @@ -1,8 +1,7 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- """ - path - ~~~~ + sphinx.testing.path + ~~~~~~~~~~~~~~~~~~~ :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. @@ -26,8 +25,8 @@ class path(text_type): def __new__(cls, s, encoding=FILESYSTEMENCODING, errors='strict'): if isinstance(s, str): s = s.decode(encoding, errors) - return text_type.__new__(cls, s) - return text_type.__new__(cls, s) + return text_type.__new__(cls, s) # type: ignore + return text_type.__new__(cls, s) # type: ignore @property def parent(self): diff --git a/tests/util.py b/sphinx/testing/util.py similarity index 89% rename from tests/util.py rename to sphinx/testing/util.py index 52c317c3a..bfb4628dd 100644 --- a/tests/util.py +++ b/sphinx/testing/util.py @@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- """ + sphinx.testing.util + ~~~~~~~~~~~~~~~~~~~ + Sphinx test suite utilities - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ - import os import re import sys @@ -28,22 +29,19 @@ from sphinx.ext.autodoc import AutoDirective from sphinx.pycode import ModuleAnalyzer from sphinx.deprecation import RemovedInSphinx17Warning -from path import path +from sphinx.testing.path import path + +if False: + from typing import List # NOQA __all__ = [ - 'rootdir', 'tempdir', - 'skip_unless_importable', 'Struct', - 'SphinxTestApp', - 'path', + 'Struct', + 'SphinxTestApp', 'SphinxTestAppWrapperForSkipBuilding', 'remove_unicode_literals', ] -rootdir = path(os.path.dirname(__file__) or '.').abspath() -tempdir = path(os.environ['SPHINX_TEST_TEMPDIR']).abspath() - - def assert_re_search(regex, text, flags=0): if not re.search(regex, text, flags): assert False, '%r did not match %r' % (regex, text) @@ -88,16 +86,6 @@ def assert_node(node, cls=None, xpath="", **kwargs): 'The node%s[%s] is not %r: %r' % (xpath, key, value, node[key]) -def skip_unless_importable(module, msg=None): - """Decorator to skip test if module is not importable.""" - try: - __import__(module) - except ImportError: - return pytest.mark.skipif(True, reason=(msg or 'conditional skip')) - else: - return pytest.mark.skipif(False, reason=(msg or 'conditional skip')) - - def etree_parse(path): with warnings.catch_warnings(record=False): warnings.filterwarnings("ignore", category=DeprecationWarning) @@ -115,22 +103,9 @@ class SphinxTestApp(application.Sphinx): better default values for the initialization parameters. """ - def __init__(self, buildername='html', testroot=None, srcdir=None, + def __init__(self, buildername='html', srcdir=None, freshenv=False, confoverrides=None, status=None, warning=None, tags=None, docutilsconf=None): - if testroot is None: - defaultsrcdir = 'root' - testroot = rootdir / 'root' - else: - defaultsrcdir = 'test-' + testroot - testroot = rootdir / 'roots' / ('test-' + testroot) - if srcdir is None: - srcdir = tempdir / defaultsrcdir - else: - srcdir = tempdir / srcdir - - if not srcdir.exists(): - testroot.copytree(srcdir) if docutilsconf is not None: (srcdir / 'docutils.conf').write_text(docutilsconf) @@ -184,6 +159,26 @@ class SphinxTestApp(application.Sphinx): return '<%s buildername=%r>' % (self.__class__.__name__, self.builder.name) +class SphinxTestAppWrapperForSkipBuilding(object): + """ + This class is a wrapper for SphinxTestApp to speed up the test by skipping + `app.build` process if it is already built and there is even one output + file. + """ + + def __init__(self, app_): + self.app = app_ + + def __getattr__(self, name): + return getattr(self.app, name) + + def build(self, *args, **kw): + if not self.app.outdir.listdir(): + # if listdir is empty, do build. + self.app.build(*args, **kw) + # otherwise, we can use built cache + + _unicode_literals_re = re.compile(r'u(".*?")|u(\'.*?\')') @@ -313,7 +308,7 @@ class ListOutput(object): """ def __init__(self, name): self.name = name - self.content = [] + self.content = [] # type: List[str] def reset(self): del self.content[:] diff --git a/tests/conftest.py b/tests/conftest.py index 5015c46f3..28dbd6ed4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,230 +1,20 @@ # -*- coding: utf-8 -*- -from __future__ import print_function +""" + pytest config for sphinx/tests + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -import sys -import subprocess -from collections import namedtuple + :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import os import pytest -from six import StringIO, string_types +from sphinx.testing.path import path -import util +pytest_plugins = 'sphinx.testing.fixtures' -@pytest.fixture -def app_params(request, test_params, shared_result): - """ - parameters that is specified by 'pytest.mark.sphinx' for - sphinx.application.Sphinx initialization - """ - - # ##### process pytest.mark.sphinx - - markers = request.node.get_marker("sphinx") - pargs = {} - kwargs = {} - - if markers is not None: - # to avoid stacking positional args - for info in reversed(list(markers)): - for i, a in enumerate(info.args): - pargs[i] = a - kwargs.update(info.kwargs) - - args = [pargs[i] for i in sorted(pargs.keys())] - - # ##### process pytest.mark.test_params - - if test_params['shared_result']: - if 'srcdir' in kwargs: - raise pytest.Exception('You can not spcify shared_result and ' - 'srcdir in same time.') - kwargs['srcdir'] = test_params['shared_result'] - restore = shared_result.restore(test_params['shared_result']) - kwargs.update(restore) - - # ##### prepare Application params - - if 'srcdir' in kwargs: - srcdir = util.tempdir / kwargs['srcdir'] - else: - srcdir = util.tempdir / kwargs.get('testroot', 'root') - kwargs['srcdir'] = srcdir - - if kwargs.get('testroot') is None: - testroot_path = util.rootdir / 'root' - else: - testroot_path = util.rootdir / 'roots' / ('test-' + kwargs['testroot']) - - if not srcdir.exists(): - testroot_path.copytree(srcdir) - - return namedtuple('app_params', 'args,kwargs')(args, kwargs) - - -@pytest.fixture -def test_params(request): - """ - test parameters that is specified by 'pytest.mark.test_params' - - :param Union[str] shared_result: - If the value is provided, app._status and app._warning objects will be - shared in the parametrized test functions and/or test functions that - have same 'shared_result' value. - **NOTE**: You can not specify shared_result and srcdir in same time. - """ - env = request.node.get_marker('test_params') - kwargs = env.kwargs if env else {} - result = { - 'shared_result': None, - } - result.update(kwargs) - - if (result['shared_result'] and - not isinstance(result['shared_result'], string_types)): - raise pytest.Exception('You can only provide a string type of value ' - 'for "shared_result" ') - return result - - -class SphinxTestAppWrapperForSkipBuilding(object): - """ - This class is a wrapper for SphinxTestApp to speed up the test by skipping - `app.build` process if it is already built and there is even one output - file. - """ - - def __init__(self, app_): - self.app = app_ - - def __getattr__(self, name): - return getattr(self.app, name) - - def build(self, *args, **kw): - if not self.app.outdir.listdir(): - # if listdir is empty, do build. - self.app.build(*args, **kw) - # otherwise, we can use built cache - - -@pytest.fixture(scope='function') -def app(test_params, app_params, make_app, shared_result): - """ - provides sphinx.application.Sphinx object - """ - args, kwargs = app_params - app_ = make_app(*args, **kwargs) - yield app_ - - print('# testroot:', kwargs.get('testroot', 'root')) - print('# builder:', app_.builder.name) - print('# srcdir:', app_.srcdir) - print('# outdir:', app_.outdir) - print('# status:', '\n' + app_._status.getvalue()) - print('# warning:', '\n' + app_._warning.getvalue()) - - if test_params['shared_result']: - shared_result.store(test_params['shared_result'], app_) - - -@pytest.fixture(scope='function') -def status(app): - """ - compat for testing with previous @with_app decorator - """ - return app._status - - -@pytest.fixture(scope='function') -def warning(app): - """ - compat for testing with previous @with_app decorator - """ - return app._warning - - -@pytest.fixture() -def make_app(test_params): - """ - provides make_app function to initialize SphinxTestApp instance. - if you want to initialize 'app' in your test function. please use this - instead of using SphinxTestApp class directory. - """ - apps = [] - syspath = sys.path[:] - - def make(*args, **kwargs): - status, warning = StringIO(), StringIO() - kwargs.setdefault('status', status) - kwargs.setdefault('warning', warning) - app_ = util.SphinxTestApp(*args, **kwargs) - apps.append(app_) - if test_params['shared_result']: - app_ = SphinxTestAppWrapperForSkipBuilding(app_) - return app_ - yield make - - sys.path[:] = syspath - for app_ in apps: - app_.cleanup() - - -class SharedResult(object): - cache = {} - - def store(self, key, app_): - if key in self.cache: - return - data = { - 'status': app_._status.getvalue(), - 'warning': app_._warning.getvalue(), - } - self.cache[key] = data - - def restore(self, key): - if key not in self.cache: - return {} - data = self.cache[key] - return { - 'status': StringIO(data['status']), - 'warning': StringIO(data['warning']), - } - - -@pytest.fixture -def shared_result(): - return SharedResult() - - -@pytest.fixture(scope='module', autouse=True) -def _shared_result_cache(): - SharedResult.cache.clear() - - -@pytest.fixture -def if_graphviz_found(app): - """ - The test will be skipped when using 'if_graphviz_found' fixture and graphviz - dot command is not found. - """ - graphviz_dot = getattr(app.config, 'graphviz_dot', '') - try: - if graphviz_dot: - dot = subprocess.Popen([graphviz_dot, '-V'], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) # show version - dot.communicate() - return - except OSError: # No such file or directory - pass - - pytest.skip('graphviz "dot" is not available') - - -@pytest.fixture -def tempdir(tmpdir): - """ - temporary directory that wrapped with `path` class. - this fixture is for compat with old test implementation. - """ - return util.path(tmpdir) +@pytest.fixture(scope='session') +def rootdir(): + return path(os.path.dirname(__file__) or '.').abspath() / 'roots' diff --git a/tests/py35/test_autodoc_py35.py b/tests/py35/test_autodoc_py35.py index 984ec603a..481374948 100644 --- a/tests/py35/test_autodoc_py35.py +++ b/tests/py35/test_autodoc_py35.py @@ -13,7 +13,7 @@ # "raises" imported for usage by autodoc import six import sys -from util import SphinxTestApp, Struct +from sphinx.testing.util import SphinxTestApp, Struct import pytest from six import StringIO @@ -25,17 +25,19 @@ from sphinx.ext.autodoc import AutoDirective, add_documenter, \ app = None -def setup_module(): +@pytest.fixture(scope='module', autouse=True) +def setup_module(rootdir, sphinx_test_tempdir): global app - app = SphinxTestApp() + srcdir = sphinx_test_tempdir / 'autodoc-root' + if not srcdir.exists(): + (rootdir/'test-root').copytree(srcdir) + app = SphinxTestApp(srcdir=srcdir) app.builder.env.app = app app.builder.env.temp_data['docname'] = 'dummy' app.connect('autodoc-process-docstring', process_docstring) app.connect('autodoc-process-signature', process_signature) app.connect('autodoc-skip-member', skip_member) - - -def teardown_module(): + yield app.cleanup() diff --git a/tests/root/Makefile b/tests/roots/test-root/Makefile similarity index 100% rename from tests/root/Makefile rename to tests/roots/test-root/Makefile diff --git a/tests/root/_static/README b/tests/roots/test-root/_static/README similarity index 100% rename from tests/root/_static/README rename to tests/roots/test-root/_static/README diff --git a/tests/root/_static/excluded.css b/tests/roots/test-root/_static/excluded.css similarity index 100% rename from tests/root/_static/excluded.css rename to tests/roots/test-root/_static/excluded.css diff --git a/tests/root/_static/subdir/foo.css b/tests/roots/test-root/_static/subdir/foo.css similarity index 100% rename from tests/root/_static/subdir/foo.css rename to tests/roots/test-root/_static/subdir/foo.css diff --git a/tests/root/_templates/contentssb.html b/tests/roots/test-root/_templates/contentssb.html similarity index 100% rename from tests/root/_templates/contentssb.html rename to tests/roots/test-root/_templates/contentssb.html diff --git a/tests/root/_templates/customsb.html b/tests/roots/test-root/_templates/customsb.html similarity index 100% rename from tests/root/_templates/customsb.html rename to tests/roots/test-root/_templates/customsb.html diff --git a/tests/root/_templates/layout.html b/tests/roots/test-root/_templates/layout.html similarity index 100% rename from tests/root/_templates/layout.html rename to tests/roots/test-root/_templates/layout.html diff --git a/tests/root/autodoc.txt b/tests/roots/test-root/autodoc.txt similarity index 100% rename from tests/root/autodoc.txt rename to tests/roots/test-root/autodoc.txt diff --git a/tests/root/autodoc_fodder.py b/tests/roots/test-root/autodoc_fodder.py similarity index 100% rename from tests/root/autodoc_fodder.py rename to tests/roots/test-root/autodoc_fodder.py diff --git a/tests/root/autodoc_missing_imports.py b/tests/roots/test-root/autodoc_missing_imports.py similarity index 100% rename from tests/root/autodoc_missing_imports.py rename to tests/roots/test-root/autodoc_missing_imports.py diff --git a/tests/root/bom.po b/tests/roots/test-root/bom.po similarity index 100% rename from tests/root/bom.po rename to tests/roots/test-root/bom.po diff --git a/tests/root/bom.txt b/tests/roots/test-root/bom.txt similarity index 100% rename from tests/root/bom.txt rename to tests/roots/test-root/bom.txt diff --git a/tests/root/conf.py b/tests/roots/test-root/conf.py similarity index 100% rename from tests/root/conf.py rename to tests/roots/test-root/conf.py diff --git a/tests/root/contents.txt b/tests/roots/test-root/contents.txt similarity index 100% rename from tests/root/contents.txt rename to tests/roots/test-root/contents.txt diff --git a/tests/root/en.lproj/localized.txt b/tests/roots/test-root/en.lproj/localized.txt similarity index 100% rename from tests/root/en.lproj/localized.txt rename to tests/roots/test-root/en.lproj/localized.txt diff --git a/tests/root/ext.py b/tests/roots/test-root/ext.py similarity index 100% rename from tests/root/ext.py rename to tests/roots/test-root/ext.py diff --git a/tests/root/extapi.txt b/tests/roots/test-root/extapi.txt similarity index 100% rename from tests/root/extapi.txt rename to tests/roots/test-root/extapi.txt diff --git a/tests/root/extensions.txt b/tests/roots/test-root/extensions.txt similarity index 100% rename from tests/root/extensions.txt rename to tests/roots/test-root/extensions.txt diff --git a/tests/root/footnote.txt b/tests/roots/test-root/footnote.txt similarity index 100% rename from tests/root/footnote.txt rename to tests/roots/test-root/footnote.txt diff --git a/tests/root/images.txt b/tests/roots/test-root/images.txt similarity index 100% rename from tests/root/images.txt rename to tests/roots/test-root/images.txt diff --git a/tests/root/img.foo.png b/tests/roots/test-root/img.foo.png similarity index 100% rename from tests/root/img.foo.png rename to tests/roots/test-root/img.foo.png diff --git a/tests/root/img.gif b/tests/roots/test-root/img.gif similarity index 100% rename from tests/root/img.gif rename to tests/roots/test-root/img.gif diff --git a/tests/root/img.pdf b/tests/roots/test-root/img.pdf similarity index 100% rename from tests/root/img.pdf rename to tests/roots/test-root/img.pdf diff --git a/tests/root/img.png b/tests/roots/test-root/img.png similarity index 100% rename from tests/root/img.png rename to tests/roots/test-root/img.png diff --git a/tests/root/includes.txt b/tests/roots/test-root/includes.txt similarity index 100% rename from tests/root/includes.txt rename to tests/roots/test-root/includes.txt diff --git a/tests/root/lists.txt b/tests/roots/test-root/lists.txt similarity index 100% rename from tests/root/lists.txt rename to tests/roots/test-root/lists.txt diff --git a/tests/root/literal.inc b/tests/roots/test-root/literal.inc similarity index 100% rename from tests/root/literal.inc rename to tests/roots/test-root/literal.inc diff --git a/tests/root/literal_orig.inc b/tests/roots/test-root/literal_orig.inc similarity index 100% rename from tests/root/literal_orig.inc rename to tests/roots/test-root/literal_orig.inc diff --git a/tests/root/markup.txt b/tests/roots/test-root/markup.txt similarity index 100% rename from tests/root/markup.txt rename to tests/roots/test-root/markup.txt diff --git a/tests/root/math.txt b/tests/roots/test-root/math.txt similarity index 100% rename from tests/root/math.txt rename to tests/roots/test-root/math.txt diff --git a/tests/root/metadata.add b/tests/roots/test-root/metadata.add similarity index 100% rename from tests/root/metadata.add rename to tests/roots/test-root/metadata.add diff --git a/tests/root/objects.txt b/tests/roots/test-root/objects.txt similarity index 100% rename from tests/root/objects.txt rename to tests/roots/test-root/objects.txt diff --git a/tests/root/otherext.foo b/tests/roots/test-root/otherext.foo similarity index 100% rename from tests/root/otherext.foo rename to tests/roots/test-root/otherext.foo diff --git a/tests/root/parsermod.py b/tests/roots/test-root/parsermod.py similarity index 100% rename from tests/root/parsermod.py rename to tests/roots/test-root/parsermod.py diff --git a/tests/root/quotes.inc b/tests/roots/test-root/quotes.inc similarity index 100% rename from tests/root/quotes.inc rename to tests/roots/test-root/quotes.inc diff --git a/tests/root/rimg.png b/tests/roots/test-root/rimg.png similarity index 100% rename from tests/root/rimg.png rename to tests/roots/test-root/rimg.png diff --git a/tests/root/robots.txt b/tests/roots/test-root/robots.txt similarity index 100% rename from tests/root/robots.txt rename to tests/roots/test-root/robots.txt diff --git a/tests/root/special/api.h b/tests/roots/test-root/special/api.h similarity index 100% rename from tests/root/special/api.h rename to tests/roots/test-root/special/api.h diff --git a/tests/root/special/code.py b/tests/roots/test-root/special/code.py similarity index 100% rename from tests/root/special/code.py rename to tests/roots/test-root/special/code.py diff --git a/tests/root/subdir.po b/tests/roots/test-root/subdir.po similarity index 100% rename from tests/root/subdir.po rename to tests/roots/test-root/subdir.po diff --git a/tests/root/subdir/excluded.txt b/tests/roots/test-root/subdir/excluded.txt similarity index 100% rename from tests/root/subdir/excluded.txt rename to tests/roots/test-root/subdir/excluded.txt diff --git a/tests/root/subdir/images.txt b/tests/roots/test-root/subdir/images.txt similarity index 100% rename from tests/root/subdir/images.txt rename to tests/roots/test-root/subdir/images.txt diff --git a/tests/root/subdir/img.png b/tests/roots/test-root/subdir/img.png similarity index 100% rename from tests/root/subdir/img.png rename to tests/roots/test-root/subdir/img.png diff --git a/tests/root/subdir/include.inc b/tests/roots/test-root/subdir/include.inc similarity index 100% rename from tests/root/subdir/include.inc rename to tests/roots/test-root/subdir/include.inc diff --git a/tests/root/subdir/includes.txt b/tests/roots/test-root/subdir/includes.txt similarity index 100% rename from tests/root/subdir/includes.txt rename to tests/roots/test-root/subdir/includes.txt diff --git a/tests/root/subdir/simg.png b/tests/roots/test-root/subdir/simg.png similarity index 100% rename from tests/root/subdir/simg.png rename to tests/roots/test-root/subdir/simg.png diff --git a/tests/root/svgimg.pdf b/tests/roots/test-root/svgimg.pdf similarity index 100% rename from tests/root/svgimg.pdf rename to tests/roots/test-root/svgimg.pdf diff --git a/tests/root/svgimg.svg b/tests/roots/test-root/svgimg.svg similarity index 100% rename from tests/root/svgimg.svg rename to tests/roots/test-root/svgimg.svg diff --git a/tests/root/tabs.inc b/tests/roots/test-root/tabs.inc similarity index 100% rename from tests/root/tabs.inc rename to tests/roots/test-root/tabs.inc diff --git a/tests/root/templated.css_t b/tests/roots/test-root/templated.css_t similarity index 100% rename from tests/root/templated.css_t rename to tests/roots/test-root/templated.css_t diff --git a/tests/root/test.inc b/tests/roots/test-root/test.inc similarity index 100% rename from tests/root/test.inc rename to tests/roots/test-root/test.inc diff --git a/tests/root/testtheme/layout.html b/tests/roots/test-root/testtheme/layout.html similarity index 100% rename from tests/root/testtheme/layout.html rename to tests/roots/test-root/testtheme/layout.html diff --git a/tests/root/testtheme/static/staticimg.png b/tests/roots/test-root/testtheme/static/staticimg.png similarity index 100% rename from tests/root/testtheme/static/staticimg.png rename to tests/roots/test-root/testtheme/static/staticimg.png diff --git a/tests/root/testtheme/static/statictmpl.html_t b/tests/roots/test-root/testtheme/static/statictmpl.html_t similarity index 100% rename from tests/root/testtheme/static/statictmpl.html_t rename to tests/roots/test-root/testtheme/static/statictmpl.html_t diff --git a/tests/root/testtheme/theme.conf b/tests/roots/test-root/testtheme/theme.conf similarity index 100% rename from tests/root/testtheme/theme.conf rename to tests/roots/test-root/testtheme/theme.conf diff --git a/tests/root/wrongenc.inc b/tests/roots/test-root/wrongenc.inc similarity index 100% rename from tests/root/wrongenc.inc rename to tests/roots/test-root/wrongenc.inc diff --git a/tests/root/ziptheme.zip b/tests/roots/test-root/ziptheme.zip similarity index 100% rename from tests/root/ziptheme.zip rename to tests/roots/test-root/ziptheme.zip diff --git a/tests/run.py b/tests/run.py index 673ad1339..a8439ba02 100755 --- a/tests/run.py +++ b/tests/run.py @@ -15,8 +15,7 @@ import os import sys import warnings import traceback - -from path import path +import shutil testroot = os.path.dirname(__file__) or '.' sys.path.insert(0, os.path.abspath(os.path.join(testroot, os.path.pardir))) @@ -46,19 +45,20 @@ os.environ['SPHINX_TEST_TEMPDIR'] = \ os.path.abspath(os.path.join(testroot, 'build')) \ if 'SPHINX_TEST_TEMPDIR' not in os.environ \ else os.path.abspath(os.environ['SPHINX_TEST_TEMPDIR']) -tempdir = path(os.environ['SPHINX_TEST_TEMPDIR']) + +tempdir = os.environ['SPHINX_TEST_TEMPDIR'] print('Temporary files will be placed in %s.' % tempdir) -if tempdir.exists(): - tempdir.rmtree() -tempdir.makedirs() +if os.path.exists(tempdir): + shutil.rmtree(tempdir) +os.makedirs(tempdir) print('Running Sphinx test suite (with Python %s)...' % sys.version.split()[0]) sys.stdout.flush() -# exclude 'root' and 'roots' dirs for pytest test collector +# exclude 'roots' dirs for pytest test collector ignore_paths = [ os.path.relpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), sub)) - for sub in ('root', 'roots') + for sub in ('roots',) ] args = sys.argv[1:] for ignore_path in ignore_paths: diff --git a/tests/test_api_translator.py b/tests/test_api_translator.py index dadea50e5..35b24732b 100644 --- a/tests/test_api_translator.py +++ b/tests/test_api_translator.py @@ -12,15 +12,14 @@ import sys import pytest -from util import rootdir -def setup_module(): - sys.path.insert(0, rootdir / 'roots' / 'test-api-set-translator') - - -def teardown_module(): - sys.path.remove(rootdir / 'roots' / 'test-api-set-translator') +@pytest.fixture(scope='module', autouse=True) +def setup_module(rootdir): + p = rootdir / 'test-api-set-translator' + sys.path.insert(0, p) + yield + sys.path.remove(p) @pytest.mark.sphinx('html') diff --git a/tests/test_apidoc.py b/tests/test_apidoc.py index a45ae9dc6..20582e9fc 100644 --- a/tests/test_apidoc.py +++ b/tests/test_apidoc.py @@ -17,13 +17,13 @@ import pytest from sphinx.apidoc import main as apidoc_main -from util import rootdir, remove_unicode_literals +from sphinx.testing.util import remove_unicode_literals @pytest.fixture() -def apidoc(tempdir, apidoc_params): +def apidoc(rootdir, tempdir, apidoc_params): _, kwargs = apidoc_params - coderoot = kwargs.get('coderoot', (rootdir / 'root')) + coderoot = rootdir / kwargs.get('coderoot', 'test-root') outdir = tempdir / 'out' args = ['sphinx-apidoc', '-o', outdir, '-F', coderoot] + kwargs.get('options', []) apidoc_main(args) @@ -46,7 +46,7 @@ def apidoc_params(request): return args, kwargs -@pytest.mark.apidoc(coderoot=(rootdir / 'root')) +@pytest.mark.apidoc(coderoot='test-root') def test_simple(make_app, apidoc): outdir = apidoc.outdir assert (outdir / 'conf.py').isfile() @@ -60,7 +60,7 @@ def test_simple(make_app, apidoc): @pytest.mark.apidoc( - coderoot=(rootdir / 'roots' / 'test-apidoc-pep420'), + coderoot='test-apidoc-pep420', options=["--implicit-namespaces"], ) def test_pep_0420_enabled(make_app, apidoc): @@ -97,7 +97,7 @@ def test_pep_0420_enabled(make_app, apidoc): assert "a.b.x namespace\n" in txt -@pytest.mark.apidoc(coderoot=(rootdir / 'roots' / 'test-apidoc-pep420')) +@pytest.mark.apidoc(coderoot='test-apidoc-pep420') def test_pep_0420_disabled(make_app, apidoc): outdir = apidoc.outdir assert (outdir / 'conf.py').isfile() @@ -111,7 +111,7 @@ def test_pep_0420_disabled(make_app, apidoc): @pytest.mark.apidoc( - coderoot=(rootdir / 'roots' / 'test-apidoc-pep420' / 'a' / 'b')) + coderoot='test-apidoc-pep420/a/b') def test_pep_0420_disabled_top_level_verify(make_app, apidoc): outdir = apidoc.outdir assert (outdir / 'conf.py').isfile() @@ -131,7 +131,7 @@ def test_pep_0420_disabled_top_level_verify(make_app, apidoc): @pytest.mark.apidoc( - coderoot=(rootdir / 'roots' / 'test-apidoc-trailing-underscore')) + coderoot='test-apidoc-trailing-underscore') def test_trailing_underscore(make_app, apidoc): outdir = apidoc.outdir assert (outdir / 'conf.py').isfile() @@ -150,7 +150,7 @@ def test_trailing_underscore(make_app, apidoc): @pytest.mark.apidoc( - coderoot=(rootdir / 'root'), + coderoot='test-root', options=[ '--doc-project', u'プロジェクト名'.encode('utf-8'), '--doc-author', u'著者名'.encode('utf-8'), @@ -178,7 +178,7 @@ def test_multibyte_parameters(make_app, apidoc): @pytest.mark.apidoc( - coderoot=(rootdir / 'root'), + coderoot='test-root', options=['--ext-mathjax'], ) def test_extension_parsed(make_app, apidoc): diff --git a/tests/test_application.py b/tests/test_application.py index 48759a895..576a01916 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -13,7 +13,7 @@ from docutils import nodes from sphinx.application import ExtensionError from sphinx.domains import Domain -from util import strip_escseq +from sphinx.testing.util import strip_escseq import pytest diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index 7857c292b..e04e38bb3 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -12,7 +12,7 @@ from six import PY3 -from util import SphinxTestApp, Struct # NOQA +from sphinx.testing.util import SphinxTestApp, Struct # NOQA import pytest import enum @@ -25,17 +25,19 @@ from sphinx.ext.autodoc import AutoDirective, add_documenter, \ app = None -def setup_module(): +@pytest.fixture(scope='module', autouse=True) +def setup_module(rootdir, sphinx_test_tempdir): global app - app = SphinxTestApp() + srcdir = sphinx_test_tempdir / 'autodoc-root' + if not srcdir.exists(): + (rootdir/'test-root').copytree(srcdir) + app = SphinxTestApp(srcdir=srcdir) app.builder.env.app = app app.builder.env.temp_data['docname'] = 'dummy' app.connect('autodoc-process-docstring', process_docstring) app.connect('autodoc-process-signature', process_signature) app.connect('autodoc-skip-member', skip_member) - - -def teardown_module(): + yield app.cleanup() diff --git a/tests/test_build.py b/tests/test_build.py index 221ea6462..cba00fb4a 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -16,7 +16,7 @@ import pytest from textwrap import dedent from sphinx.errors import SphinxError -from util import rootdir, tempdir, path +from sphinx.testing.path import path def request_session_head(url, **kwargs): @@ -27,14 +27,14 @@ def request_session_head(url, **kwargs): @pytest.fixture -def nonascii_srcdir(request): +def nonascii_srcdir(request, rootdir, sphinx_test_tempdir): # If supported, build in a non-ASCII source dir test_name = u'\u65e5\u672c\u8a9e' - basedir = tempdir / request.node.originalname + basedir = sphinx_test_tempdir / request.node.originalname try: srcdir = basedir / test_name if not srcdir.exists(): - (rootdir / 'root').copytree(srcdir) + (rootdir / 'test-root').copytree(srcdir) except UnicodeEncodeError: srcdir = basedir / 'all' else: diff --git a/tests/test_build_applehelp.py b/tests/test_build_applehelp.py index 14b856091..4418cb265 100644 --- a/tests/test_build_applehelp.py +++ b/tests/test_build_applehelp.py @@ -14,7 +14,7 @@ import plistlib import pytest -from path import path +from sphinx.testing.path import path # Use plistlib.load in 3.4 and above try: diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 58c72c780..297334f0d 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -17,7 +17,7 @@ from six import PY3 from sphinx import __display_version__ from sphinx.util.inventory import InventoryFile -from util import remove_unicode_literals, strip_escseq +from sphinx.testing.util import remove_unicode_literals, strip_escseq import xml.etree.cElementTree as ElementTree from html5lib import getTreeBuilder, HTMLParser import pytest diff --git a/tests/test_build_html5.py b/tests/test_build_html5.py index d381510a0..d24bac570 100644 --- a/tests/test_build_html5.py +++ b/tests/test_build_html5.py @@ -21,7 +21,7 @@ from html5lib import getTreeBuilder, HTMLParser from sphinx.util.docutils import is_html5_writer_available -from util import skip_unless +from sphinx.testing.util import skip_unless from test_build_html import flat_dict, tail_check, check_xpath TREE_BUILDER = getTreeBuilder('etree', implementation=ElementTree) diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index ae9080d13..63772462d 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -24,7 +24,7 @@ from sphinx.util.osutil import cd, ensuredir from sphinx.util import docutils from sphinx.writers.latex import LaTeXTranslator -from util import SkipTest, remove_unicode_literals, strip_escseq, skip_if +from sphinx.testing.util import SkipTest, remove_unicode_literals, strip_escseq, skip_if from test_build_html import ENV_WARNINGS diff --git a/tests/test_build_texinfo.py b/tests/test_build_texinfo.py index 0177bc392..99c26667f 100644 --- a/tests/test_build_texinfo.py +++ b/tests/test_build_texinfo.py @@ -19,7 +19,7 @@ import pytest from sphinx.writers.texinfo import TexinfoTranslator -from util import SkipTest, remove_unicode_literals, strip_escseq +from sphinx.testing.util import SkipTest, remove_unicode_literals, strip_escseq from test_build_html import ENV_WARNINGS diff --git a/tests/test_build_text.py b/tests/test_build_text.py index 6ce3b5276..1732b3187 100644 --- a/tests/test_build_text.py +++ b/tests/test_build_text.py @@ -12,7 +12,7 @@ from docutils.utils import column_width from sphinx.writers.text import MAXWIDTH -from util import with_app +from sphinx.testing.util import with_app def with_text_app(*args, **kw): diff --git a/tests/test_catalogs.py b/tests/test_catalogs.py index 64f2acb9a..b3e17a0a1 100644 --- a/tests/test_catalogs.py +++ b/tests/test_catalogs.py @@ -12,37 +12,36 @@ import shutil import pytest -from util import find_files, rootdir, tempdir - -root = tempdir / 'test-intl' -build_dir = root / '_build' -locale_dir = build_dir / 'locale' +from sphinx.testing.util import find_files @pytest.fixture -def setup_test(): - # delete remnants left over after failed build - root.rmtree(True) - (rootdir / 'roots' / 'test-intl').copytree(root) +def setup_test(app_params): + srcdir = app_params.kwargs['srcdir'] + locale_dir = srcdir / 'locale' # copy all catalogs into locale layout directory - for po in find_files(root, '.po'): + for po in find_files(srcdir, '.po'): copy_po = (locale_dir / 'en' / 'LC_MESSAGES' / po) if not copy_po.parent.exists(): copy_po.parent.makedirs() - shutil.copy(root / po, copy_po) + shutil.copy(srcdir / po, copy_po) yield - build_dir.rmtree(True) + # delete remnants left over after failed build + locale_dir.rmtree(True) + (srcdir / '_build').rmtree(True) @pytest.mark.usefixtures('setup_test') +@pytest.mark.test_params(shared_result='test-catalogs') @pytest.mark.sphinx( 'html', testroot='intl', - confoverrides={'language': 'en', 'locale_dirs': [locale_dir]}) + confoverrides={'language': 'en', 'locale_dirs': ['./locale']}) def test_compile_all_catalogs(app, status, warning): app.builder.compile_all_catalogs() + locale_dir = app.srcdir / 'locale' catalog_dir = locale_dir / app.config.language / 'LC_MESSAGES' expect = set([ x.replace('.po', '.mo') @@ -54,10 +53,12 @@ def test_compile_all_catalogs(app, status, warning): @pytest.mark.usefixtures('setup_test') +@pytest.mark.test_params(shared_result='test-catalogs') @pytest.mark.sphinx( - 'html', testroot='intl', - confoverrides={'language': 'en', 'locale_dirs': [locale_dir]}) + 'html', testroot='intl', + confoverrides={'language': 'en', 'locale_dirs': ['./locale']}) def test_compile_specific_catalogs(app, status, warning): + locale_dir = app.srcdir / 'locale' catalog_dir = locale_dir / app.config.language / 'LC_MESSAGES' def get_actual(): @@ -70,12 +71,14 @@ def test_compile_specific_catalogs(app, status, warning): @pytest.mark.usefixtures('setup_test') +@pytest.mark.test_params(shared_result='test-catalogs') @pytest.mark.sphinx( - 'html', testroot='intl', - confoverrides={'language': 'en', 'locale_dirs': [locale_dir]}) + 'html', testroot='intl', + confoverrides={'language': 'en', 'locale_dirs': ['./locale']}) def test_compile_update_catalogs(app, status, warning): app.builder.compile_update_catalogs() + locale_dir = app.srcdir / 'locale' catalog_dir = locale_dir / app.config.language / 'LC_MESSAGES' expect = set([ x.replace('.po', '.mo') diff --git a/tests/test_config.py b/tests/test_config.py index a026f3d2e..f9300c30e 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -16,6 +16,7 @@ import mock import sphinx from sphinx.config import Config from sphinx.errors import ExtensionError, ConfigError, VersionRequirementError +from sphinx.testing.path import path @pytest.mark.sphinx(confoverrides={ @@ -129,8 +130,19 @@ def test_errors_if_setup_is_not_callable(tempdir, make_app): assert 'callable' in str(excinfo.value) +@pytest.fixture +def make_app_with_empty_project(make_app, tempdir): + (tempdir / 'conf.py').write_text('') + + def _make_app(*args, **kw): + kw.setdefault('srcdir', path(tempdir)) + return make_app(*args, **kw) + return _make_app + + @mock.patch.object(sphinx, '__display_version__', '1.3.4') -def test_needs_sphinx(make_app): +def test_needs_sphinx(make_app_with_empty_project): + make_app = make_app_with_empty_project # micro version app = make_app(confoverrides={'needs_sphinx': '1.3.3'}) # OK: less app.cleanup() diff --git a/tests/test_directive_code.py b/tests/test_directive_code.py index 0e702803d..5f67c5627 100644 --- a/tests/test_directive_code.py +++ b/tests/test_directive_code.py @@ -13,43 +13,52 @@ import pytest from sphinx.config import Config from sphinx.directives.code import LiteralIncludeReader -from util import etree_parse, rootdir +from sphinx.testing.util import etree_parse -TESTROOT_PATH = rootdir / 'roots' / 'test-directive-code' -LITERAL_INC_PATH = TESTROOT_PATH / 'literal.inc' DUMMY_CONFIG = Config(None, None, {}, '') -def test_LiteralIncludeReader(): +@pytest.fixture(scope='module') +def testroot(rootdir): + testroot_path = rootdir / 'test-directive-code' + return testroot_path + + +@pytest.fixture(scope='module') +def literal_inc_path(testroot): + return testroot / 'literal.inc' + + +def test_LiteralIncludeReader(literal_inc_path): options = {'lineno-match': True} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() - assert content == LITERAL_INC_PATH.text() + assert content == literal_inc_path.text() assert lines == 14 assert reader.lineno_start == 1 -def test_LiteralIncludeReader_lineno_start(): +def test_LiteralIncludeReader_lineno_start(literal_inc_path): options = {'lineno-start': 5} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() - assert content == LITERAL_INC_PATH.text() + assert content == literal_inc_path.text() assert lines == 14 assert reader.lineno_start == 5 -def test_LiteralIncludeReader_pyobject1(): +def test_LiteralIncludeReader_pyobject1(literal_inc_path): options = {'lineno-match': True, 'pyobject': 'Foo'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() assert content == ("class Foo:\n" " pass\n") assert reader.lineno_start == 6 -def test_LiteralIncludeReader_pyobject2(): +def test_LiteralIncludeReader_pyobject2(literal_inc_path): options = {'pyobject': 'Bar'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() assert content == ("class Bar:\n" " def baz():\n" @@ -57,25 +66,25 @@ def test_LiteralIncludeReader_pyobject2(): assert reader.lineno_start == 1 # no lineno-match -def test_LiteralIncludeReader_pyobject3(): +def test_LiteralIncludeReader_pyobject3(literal_inc_path): options = {'pyobject': 'Bar.baz'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() assert content == (" def baz():\n" " pass\n") -def test_LiteralIncludeReader_pyobject_and_lines(): +def test_LiteralIncludeReader_pyobject_and_lines(literal_inc_path): options = {'pyobject': 'Bar', 'lines': '2-'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() assert content == (" def baz():\n" " pass\n") -def test_LiteralIncludeReader_lines1(): +def test_LiteralIncludeReader_lines1(literal_inc_path): options = {'lines': '1-4'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() assert content == (u"# Literally included file using Python highlighting\n" u"# -*- coding: utf-8 -*-\n" @@ -83,18 +92,18 @@ def test_LiteralIncludeReader_lines1(): u"foo = \"Including Unicode characters: üöä\"\n") -def test_LiteralIncludeReader_lines2(): +def test_LiteralIncludeReader_lines2(literal_inc_path): options = {'lines': '1,4,6'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() assert content == (u"# Literally included file using Python highlighting\n" u"foo = \"Including Unicode characters: üöä\"\n" u"class Foo:\n") -def test_LiteralIncludeReader_lines_and_lineno_match1(): +def test_LiteralIncludeReader_lines_and_lineno_match1(literal_inc_path): options = {'lines': '4-6', 'lineno-match': True} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() assert content == (u"foo = \"Including Unicode characters: üöä\"\n" u"\n" @@ -103,24 +112,24 @@ def test_LiteralIncludeReader_lines_and_lineno_match1(): @pytest.mark.sphinx() # init locale for errors -def test_LiteralIncludeReader_lines_and_lineno_match2(app, status, warning): +def test_LiteralIncludeReader_lines_and_lineno_match2(literal_inc_path, app, status, warning): options = {'lines': '1,4,6', 'lineno-match': True} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) with pytest.raises(ValueError): content, lines = reader.read() @pytest.mark.sphinx() # init locale for errors -def test_LiteralIncludeReader_lines_and_lineno_match3(app, status, warning): +def test_LiteralIncludeReader_lines_and_lineno_match3(literal_inc_path, app, status, warning): options = {'lines': '100-', 'lineno-match': True} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) with pytest.raises(ValueError): content, lines = reader.read() -def test_LiteralIncludeReader_start_at(): +def test_LiteralIncludeReader_start_at(literal_inc_path): options = {'lineno-match': True, 'start-at': 'Foo', 'end-at': 'Bar'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() assert content == ("class Foo:\n" " pass\n" @@ -129,19 +138,19 @@ def test_LiteralIncludeReader_start_at(): assert reader.lineno_start == 6 -def test_LiteralIncludeReader_start_after(): +def test_LiteralIncludeReader_start_after(literal_inc_path): options = {'lineno-match': True, 'start-after': 'Foo', 'end-before': 'Bar'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() assert content == (" pass\n" "\n") assert reader.lineno_start == 7 -def test_LiteralIncludeReader_start_after_and_lines(): +def test_LiteralIncludeReader_start_after_and_lines(literal_inc_path): options = {'lineno-match': True, 'lines': '6-', 'start-after': 'coding', 'end-before': 'comment'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() assert content == ("\n" "class Bar:\n" @@ -151,9 +160,9 @@ def test_LiteralIncludeReader_start_after_and_lines(): assert reader.lineno_start == 8 -def test_LiteralIncludeReader_start_at_and_lines(): +def test_LiteralIncludeReader_start_at_and_lines(literal_inc_path): options = {'lines': '2, 3, 5', 'start-at': 'foo', 'end-before': '#'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() assert content == ("\n" "class Foo:\n" @@ -161,41 +170,41 @@ def test_LiteralIncludeReader_start_at_and_lines(): assert reader.lineno_start == 1 -def test_LiteralIncludeReader_missing_start_and_end(): +def test_LiteralIncludeReader_missing_start_and_end(literal_inc_path): options = {'start-at': 'NOTHING'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) with pytest.raises(ValueError): content, lines = reader.read() options = {'end-at': 'NOTHING'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) with pytest.raises(ValueError): content, lines = reader.read() options = {'start-after': 'NOTHING'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) with pytest.raises(ValueError): content, lines = reader.read() options = {'end-before': 'NOTHING'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) with pytest.raises(ValueError): content, lines = reader.read() -def test_LiteralIncludeReader_prepend(): +def test_LiteralIncludeReader_prepend(literal_inc_path): options = {'lines': '1', 'prepend': 'Hello', 'append': 'Sphinx'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() assert content == ("Hello\n" "# Literally included file using Python highlighting\n" "Sphinx\n") -def test_LiteralIncludeReader_dedent(): +def test_LiteralIncludeReader_dedent(literal_inc_path): # dedent: 2 options = {'lines': '10-12', 'dedent': 2} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() assert content == (" def baz():\n" " pass\n" @@ -203,7 +212,7 @@ def test_LiteralIncludeReader_dedent(): # dedent: 4 options = {'lines': '10-12', 'dedent': 4} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() assert content == ("def baz():\n" " pass\n" @@ -211,17 +220,17 @@ def test_LiteralIncludeReader_dedent(): # dedent: 6 options = {'lines': '10-12', 'dedent': 6} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() assert content == ("f baz():\n" " pass\n" "\n") -def test_LiteralIncludeReader_tabwidth(): +def test_LiteralIncludeReader_tabwidth(testroot): # tab-width: 4 options = {'tab-width': 4, 'pyobject': 'Qux'} - reader = LiteralIncludeReader(TESTROOT_PATH / 'target.py', options, DUMMY_CONFIG) + reader = LiteralIncludeReader(testroot / 'target.py', options, DUMMY_CONFIG) content, lines = reader.read() assert content == ("class Qux:\n" " def quux(self):\n" @@ -229,27 +238,27 @@ def test_LiteralIncludeReader_tabwidth(): # tab-width: 8 options = {'tab-width': 8, 'pyobject': 'Qux'} - reader = LiteralIncludeReader(TESTROOT_PATH / 'target.py', options, DUMMY_CONFIG) + reader = LiteralIncludeReader(testroot / 'target.py', options, DUMMY_CONFIG) content, lines = reader.read() assert content == ("class Qux:\n" " def quux(self):\n" " pass\n") -def test_LiteralIncludeReader_tabwidth_dedent(): +def test_LiteralIncludeReader_tabwidth_dedent(testroot): options = {'tab-width': 4, 'dedent': 4, 'pyobject': 'Qux.quux'} - reader = LiteralIncludeReader(TESTROOT_PATH / 'target.py', options, DUMMY_CONFIG) + reader = LiteralIncludeReader(testroot / 'target.py', options, DUMMY_CONFIG) content, lines = reader.read() assert content == ("def quux(self):\n" " pass\n") -def test_LiteralIncludeReader_diff(): - options = {'diff': TESTROOT_PATH / 'literal-diff.inc'} - reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG) +def test_LiteralIncludeReader_diff(testroot, literal_inc_path): + options = {'diff': testroot / 'literal-diff.inc'} + reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG) content, lines = reader.read() - assert content == ("--- " + TESTROOT_PATH + "/literal-diff.inc\n" - "+++ " + TESTROOT_PATH + "/literal.inc\n" + assert content == ("--- " + testroot + "/literal-diff.inc\n" + "+++ " + testroot + "/literal.inc\n" "@@ -7,8 +7,8 @@\n" " pass\n" " \n" diff --git a/tests/test_docutilsconf.py b/tests/test_docutilsconf.py index 3c43b6e7c..b19d856cb 100644 --- a/tests/test_docutilsconf.py +++ b/tests/test_docutilsconf.py @@ -12,7 +12,8 @@ import re import pytest -from util import path, SkipTest +from sphinx.testing.path import path +from sphinx.testing.util import SkipTest def regex_count(expr, result): @@ -77,7 +78,7 @@ def test_docutils_source_link_with_nonascii_file(app, status, warning): try: (srcdir / (mb_name + '.txt')).write_text('') except UnicodeEncodeError: - from path import FILESYSTEMENCODING + from sphinx.testing.path import FILESYSTEMENCODING raise SkipTest( 'nonascii filename not supported on this filesystem encoding: ' '%s', FILESYSTEMENCODING) diff --git a/tests/test_domain_js.py b/tests/test_domain_js.py index 5853d3b9f..22faf4458 100644 --- a/tests/test_domain_js.py +++ b/tests/test_domain_js.py @@ -16,7 +16,7 @@ from docutils import nodes from sphinx import addnodes from sphinx.domains.javascript import JavaScriptDomain -from util import assert_node +from sphinx.testing.util import assert_node @pytest.mark.sphinx('dummy', testroot='domain-js') diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py index 383dd8d33..28743f9e1 100644 --- a/tests/test_domain_py.py +++ b/tests/test_domain_py.py @@ -17,7 +17,7 @@ from docutils import nodes from sphinx import addnodes from sphinx.domains.python import py_sig_re, _pseudo_parse_arglist, PythonDomain -from util import assert_node +from sphinx.testing.util import assert_node def parse(sig): diff --git a/tests/test_environment.py b/tests/test_environment.py index 22baab0dd..611d34577 100644 --- a/tests/test_environment.py +++ b/tests/test_environment.py @@ -8,22 +8,24 @@ :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +import pytest -from util import SphinxTestApp, path - +from sphinx.testing.util import SphinxTestApp, path from sphinx.builders.html import StandaloneHTMLBuilder from sphinx.builders.latex import LaTeXBuilder app = env = None -def setup_module(): +@pytest.fixture(scope='module', autouse=True) +def setup_module(rootdir, sphinx_test_tempdir): global app, env - app = SphinxTestApp(srcdir='root-envtest') + srcdir = sphinx_test_tempdir / 'root-envtest' + if not srcdir.exists(): + (rootdir/'test-root').copytree(srcdir) + app = SphinxTestApp(srcdir=srcdir) env = app.env - - -def teardown_module(): + yield app.cleanup() diff --git a/tests/test_environment_toctree.py b/tests/test_environment_toctree.py index a2d54fb79..db07aa479 100644 --- a/tests/test_environment_toctree.py +++ b/tests/test_environment_toctree.py @@ -16,7 +16,7 @@ from sphinx.addnodes import compact_paragraph, only from sphinx.builders.html import StandaloneHTMLBuilder import pytest -from util import assert_node +from sphinx.testing.util import assert_node @pytest.mark.sphinx('xml', testroot='toctree') diff --git a/tests/test_ext_autosummary.py b/tests/test_ext_autosummary.py index b963117b7..ddd033154 100644 --- a/tests/test_ext_autosummary.py +++ b/tests/test_ext_autosummary.py @@ -13,7 +13,7 @@ from six import iteritems, StringIO from sphinx.ext.autosummary import mangle_signature -from util import etree_parse +from sphinx.testing.util import etree_parse import pytest diff --git a/tests/test_ext_inheritance_diagram.py b/tests/test_ext_inheritance_diagram.py index 5c4e5b673..6a2652514 100644 --- a/tests/test_ext_inheritance_diagram.py +++ b/tests/test_ext_inheritance_diagram.py @@ -11,7 +11,6 @@ import re import sys -from util import rootdir from sphinx.ext.inheritance_diagram import InheritanceException, import_classes import pytest @@ -44,12 +43,12 @@ def test_inheritance_diagram_latex(app, status, warning): assert re.search(pattern, content, re.M) -def test_import_classes(): +def test_import_classes(rootdir): from sphinx.application import Sphinx, TemplateBridge from sphinx.util.i18n import CatalogInfo try: - sys.path.append(rootdir / 'roots/test-ext-inheritance_diagram') + sys.path.append(rootdir / 'test-ext-inheritance_diagram') from example.sphinx import DummyClass # got exception for unknown class or module diff --git a/tests/test_ext_math.py b/tests/test_ext_math.py index 296bba94f..552be96f3 100644 --- a/tests/test_ext_math.py +++ b/tests/test_ext_math.py @@ -12,7 +12,7 @@ import re import pytest -from util import SkipTest +from sphinx.testing.util import SkipTest @pytest.mark.sphinx( diff --git a/tests/test_intl.py b/tests/test_intl.py index cd5488779..5a6c1c9af 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -20,7 +20,7 @@ from babel.messages import pofile, mofile from six import string_types import pytest -from util import ( +from sphinx.testing.util import ( path, etree_parse, strip_escseq, assert_re_search, assert_not_re_search, assert_startswith, assert_node ) @@ -494,15 +494,15 @@ def test_gettext_buildr_ignores_only_directive(app): @sphinx_intl +# use individual shared_result directory to avoid "incompatible doctree" error +@pytest.mark.test_params(shared_result='test_gettext_dont_rebuild_mo') def test_gettext_dont_rebuild_mo(make_app, app_params, build_mo): # --- don't rebuild by .mo mtime def get_number_of_update_targets(app_): updated = app_.env.update(app_.config, app_.srcdir, app_.doctreedir) return len(updated) - # setup new directory args, kwargs = app_params - kwargs['srcdir'] = 'test_gettext_dont_rebuild_mo' # phase1: build document with non-gettext builder and generate mo file in srcdir app0 = make_app('dummy', *args, **kwargs) diff --git a/tests/test_markup.py b/tests/test_markup.py index 18c9d0bbd..9690f2bf9 100644 --- a/tests/test_markup.py +++ b/tests/test_markup.py @@ -23,7 +23,7 @@ from sphinx.writers.html import HTMLWriter, HTMLTranslator from sphinx.writers.latex import LaTeXWriter, LaTeXTranslator import pytest -from util import assert_node +from sphinx.testing.util import assert_node @pytest.fixture diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py index 6195e6216..b95356aaa 100644 --- a/tests/test_quickstart.py +++ b/tests/test_quickstart.py @@ -16,7 +16,7 @@ from six import PY2, text_type, StringIO from six.moves import input import pytest -from util import SkipTest +from sphinx.testing.util import SkipTest from sphinx import application from sphinx import quickstart as qs diff --git a/tests/test_setup_command.py b/tests/test_setup_command.py index 70c6b796f..562b0a715 100644 --- a/tests/test_setup_command.py +++ b/tests/test_setup_command.py @@ -18,19 +18,11 @@ import sphinx import pytest from sphinx.util.osutil import cd -from util import rootdir, tempdir from textwrap import dedent -root = tempdir / 'test-setup' - - -def setup_module(): - if not root.exists(): - (rootdir / 'roots' / 'test-setup').copytree(root) - @pytest.fixture -def setup_command(request, tempdir): +def setup_command(request, tempdir, rootdir): """ Run `setup.py build_sphinx` with args and kwargs, pass it to the test and clean up properly. @@ -38,8 +30,8 @@ def setup_command(request, tempdir): marker = request.node.get_marker('setup_command') args = marker.args if marker else [] - pkgrootdir = tempdir / 'root' - root.copytree(pkgrootdir) + pkgrootdir = tempdir / 'test-setup' + (rootdir / 'test-setup').copytree(pkgrootdir) with cd(pkgrootdir): pythonpath = os.path.dirname(os.path.dirname(sphinx.__file__)) @@ -89,7 +81,7 @@ def nonascii_srcdir(request, setup_command): try: (srcdir / mb_name).makedirs() except UnicodeEncodeError: - from path import FILESYSTEMENCODING + from sphinx.testing.path import FILESYSTEMENCODING pytest.skip( 'non-ASCII filename not supported on this filesystem encoding: ' '%s' % FILESYSTEMENCODING) diff --git a/tests/test_util.py b/tests/test_util.py index 0a481db2a..b0543a246 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -17,7 +17,7 @@ from sphinx.util import ( display_chunk, encode_uri, parselinenos, split_docinfo, status_iterator ) -from util import strip_escseq +from sphinx.testing.util import strip_escseq def test_encode_uri(): diff --git a/tests/test_util_images.py b/tests/test_util_images.py index 45ee66c55..6f67dcc82 100644 --- a/tests/test_util_images.py +++ b/tests/test_util_images.py @@ -16,23 +16,25 @@ from sphinx.util.images import ( get_image_size, guess_mimetype, get_image_extension, parse_data_uri ) -from util import rootdir +GIF_FILENAME = 'img.gif' +PNG_FILENAME = 'img.png' +PDF_FILENAME = 'img.pdf' +TXT_FILENAME = 'contents.txt' -GIF_FILENAME = rootdir / 'root' / 'img.gif' -PNG_FILENAME = rootdir / 'root' / 'img.png' -PDF_FILENAME = rootdir / 'root' / 'img.pdf' -TXT_FILENAME = rootdir / 'root' / 'contents.txt' +@pytest.fixture(scope='module') +def testroot(rootdir): + return rootdir / 'test-root' -def test_get_image_size(): - assert get_image_size(GIF_FILENAME) == (200, 181) - assert get_image_size(PNG_FILENAME) == (200, 181) - assert get_image_size(PDF_FILENAME) is None - assert get_image_size(TXT_FILENAME) is None +def test_get_image_size(testroot): + assert get_image_size(testroot / GIF_FILENAME) == (200, 181) + assert get_image_size(testroot / PNG_FILENAME) == (200, 181) + assert get_image_size(testroot / PDF_FILENAME) is None + assert get_image_size(testroot / TXT_FILENAME) is None -def test_guess_mimetype(): +def test_guess_mimetype(testroot): # guess by filename assert guess_mimetype('img.png') == 'image/png' assert guess_mimetype('img.jpg') == 'image/jpeg' @@ -42,21 +44,22 @@ def test_guess_mimetype(): assert guess_mimetype('IMG.PNG') == 'image/png' # guess by content - assert guess_mimetype(content=GIF_FILENAME.bytes()) == 'image/gif' - assert guess_mimetype(content=PNG_FILENAME.bytes()) == 'image/png' - assert guess_mimetype(content=PDF_FILENAME.bytes()) is None - assert guess_mimetype(content=TXT_FILENAME.bytes()) is None - assert guess_mimetype(content=TXT_FILENAME.bytes(), default='text/plain') == 'text/plain' + assert guess_mimetype(content=(testroot/GIF_FILENAME).bytes()) == 'image/gif' + assert guess_mimetype(content=(testroot/PNG_FILENAME).bytes()) == 'image/png' + assert guess_mimetype(content=(testroot/PDF_FILENAME).bytes()) is None + assert guess_mimetype(content=(testroot/TXT_FILENAME).bytes()) is None + assert guess_mimetype(content=(testroot/TXT_FILENAME).bytes(), + default='text/plain') == 'text/plain' # the priority of params: filename > content > default assert guess_mimetype('img.png', - content=GIF_FILENAME.bytes(), + content=(testroot/GIF_FILENAME).bytes(), default='text/plain') == 'image/png' assert guess_mimetype('no_extension', - content=GIF_FILENAME.bytes(), + content=(testroot/GIF_FILENAME).bytes(), default='text/plain') == 'image/gif' assert guess_mimetype('no_extension', - content=TXT_FILENAME.bytes(), + content=(testroot/TXT_FILENAME).bytes(), default='text/plain') == 'text/plain' diff --git a/tests/test_util_logging.py b/tests/test_util_logging.py index ca46b8328..4d93d5112 100644 --- a/tests/test_util_logging.py +++ b/tests/test_util_logging.py @@ -20,7 +20,7 @@ from sphinx.util.logging import is_suppressed_warning from sphinx.util.parallel import ParallelTasks import pytest -from util import strip_escseq +from sphinx.testing.util import strip_escseq def test_info_and_warning(app, status, warning): diff --git a/tests/test_versioning.py b/tests/test_versioning.py index 0727d7c4a..b73c00fa6 100644 --- a/tests/test_versioning.py +++ b/tests/test_versioning.py @@ -11,28 +11,31 @@ import pickle +import pytest from docutils.parsers.rst.directives.html import MetaBody from sphinx import addnodes from sphinx.versioning import add_uids, merge_doctrees, get_ratio -from util import SphinxTestApp +from sphinx.testing.util import SphinxTestApp app = original = original_uids = None -def setup_module(): +@pytest.fixture(scope='module', autouse=True) +def setup_module(rootdir, sphinx_test_tempdir): global app, original, original_uids - app = SphinxTestApp(testroot='versioning') + srcdir = sphinx_test_tempdir / 'test-versioning' + if not srcdir.exists(): + (rootdir/'test-versioning').copytree(srcdir) + app = SphinxTestApp(srcdir=srcdir) app.builder.env.app = app app.connect('doctree-resolved', on_doctree_resolved) app.build() original = doctrees['original'] original_uids = [n.uid for n in add_uids(original, is_paragraph)] - - -def teardown_module(): + yield app.cleanup() diff --git a/tests/test_websupport.py b/tests/test_websupport.py index ea5777c77..93ed637be 100644 --- a/tests/test_websupport.py +++ b/tests/test_websupport.py @@ -16,17 +16,16 @@ except ImportError: sqlalchemy_missing = True import pytest -from util import rootdir, tempdir @pytest.mark.skipif(sqlalchemy_missing, reason='needs sqlalchemy') -def test_build(request): +def test_build(request, rootdir, sphinx_test_tempdir): settings = { - 'srcdir': rootdir / 'roots' / 'test-basic', + 'srcdir': rootdir / 'test-basic', # to use same directory for 'builddir' in each 'support' fixture, using - # 'tempdir' (static) value instead of 'tempdir' fixture value. + # 'sphinx_test_tempdir' (static) value instead of 'tempdir' fixture value. # each test expect result of db value at previous test case. - 'builddir': tempdir / 'websupport' + 'builddir': sphinx_test_tempdir / 'websupport' } marker = request.node.get_marker('support') if marker: