summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py34
-rwxr-xr-xtests/run.py59
-rw-r--r--tests/test_pycode.py3
3 files changed, 36 insertions, 60 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 9ea99dbd9..0d6b39681 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -8,7 +8,9 @@
"""
import os
+import shutil
import sys
+import warnings
import pytest
from sphinx.testing.path import path
@@ -26,3 +28,35 @@ if sys.version_info < (3, 5):
@pytest.fixture(scope='session')
def rootdir():
return path(os.path.dirname(__file__) or '.').abspath() / 'roots'
+
+
+def pytest_report_header(config):
+ return 'Running Sphinx test suite (with Python %s)...' % (
+ sys.version.split()[0])
+
+
+def _filter_warnings():
+ def ignore(**kwargs): warnings.filterwarnings('ignore', **kwargs)
+
+ ignore(category=DeprecationWarning, module='site') # virtualenv
+ ignore(category=PendingDeprecationWarning, module=r'_pytest\..*')
+ ignore(category=ImportWarning, module='pkgutil')
+
+
+def _initialize_test_directory(session):
+ testroot = os.path.join(str(session.config.rootdir), 'tests')
+ tempdir = os.path.abspath(os.getenv('SPHINX_TEST_TEMPDIR',
+ os.path.join(testroot, 'build')))
+ os.environ['SPHINX_TEST_TEMPDIR'] = tempdir
+
+ print('Temporary files will be placed in %s.' % tempdir)
+
+ if os.path.exists(tempdir):
+ shutil.rmtree(tempdir)
+
+ os.makedirs(tempdir)
+
+
+def pytest_sessionstart(session):
+ _filter_warnings()
+ _initialize_test_directory(session)
diff --git a/tests/run.py b/tests/run.py
deleted file mode 100755
index 2116e345c..000000000
--- a/tests/run.py
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""
- Sphinx unit test driver
- ~~~~~~~~~~~~~~~~~~~~~~~
-
- This script runs the Sphinx unit test suite.
-
- :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
- :license: BSD, see LICENSE for details.
-"""
-from __future__ import print_function
-
-import os
-import sys
-import warnings
-import traceback
-import shutil
-
-testroot = os.path.dirname(__file__) or '.'
-sys.path.insert(0, os.path.abspath(os.path.join(testroot, os.path.pardir)))
-
-# filter warnings of test dependencies
-warnings.filterwarnings('ignore', category=DeprecationWarning, module='site') # virtualenv
-warnings.filterwarnings('ignore', category=ImportWarning, module='backports')
-warnings.filterwarnings('ignore', category=ImportWarning, module='pkgutil')
-warnings.filterwarnings('ignore', category=ImportWarning, module='pytest_cov')
-warnings.filterwarnings('ignore', category=PendingDeprecationWarning, module=r'_pytest\..*')
-
-# check dependencies before testing
-print('Checking dependencies...')
-for modname in ('pytest', 'mock', 'six', 'docutils', 'jinja2', 'pygments',
- 'snowballstemmer', 'babel', 'html5lib'):
- try:
- __import__(modname)
- except ImportError as err:
- if modname == 'mock' and sys.version_info[0] == 3:
- continue
- traceback.print_exc()
- print('The %r package is needed to run the Sphinx test suite.' % modname)
- sys.exit(1)
-
-# find a temp dir for testing and clean it up now
-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 = os.environ['SPHINX_TEST_TEMPDIR']
-print('Temporary files will be placed in %s.' % tempdir)
-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()
-
-import pytest # NOQA
-sys.exit(pytest.main(sys.argv[1:]))
diff --git a/tests/test_pycode.py b/tests/test_pycode.py
index 2b5ae1514..400c47dc5 100644
--- a/tests/test_pycode.py
+++ b/tests/test_pycode.py
@@ -41,7 +41,8 @@ def test_ModuleAnalyzer_for_file():
def test_ModuleAnalyzer_for_module():
analyzer = ModuleAnalyzer.for_module('sphinx')
assert analyzer.modname == 'sphinx'
- assert analyzer.srcname == SPHINX_MODULE_PATH
+ assert analyzer.srcname in (SPHINX_MODULE_PATH,
+ os.path.abspath(SPHINX_MODULE_PATH))
assert analyzer.encoding == 'utf-8'