sphinx/tests/run.py

69 lines
2.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Sphinx unit test driver
~~~~~~~~~~~~~~~~~~~~~~~
This script runs the Sphinx unit test suite.
2017-03-22 06:21:12 -05:00
: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')
2017-04-27 07:24:12 -05:00
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...')
2017-01-03 07:24:00 -06:00
for modname in ('pytest', 'mock', 'six', 'docutils', 'jinja2', 'pygments',
'snowballstemmer', 'babel', 'html5lib'):
try:
__import__(modname)
except ImportError as err:
2014-09-21 10:32:52 -05:00
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()
# exclude 'roots' dirs for pytest test collector
2017-01-03 07:24:00 -06:00
ignore_paths = [
os.path.relpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), sub))
for sub in ('roots',)
2017-01-03 07:24:00 -06:00
]
args = sys.argv[1:]
2017-01-25 10:13:17 -06:00
for ignore_path in ignore_paths:
args.extend(['--ignore', ignore_path])
2017-01-03 07:24:00 -06:00
2017-01-25 10:13:17 -06:00
import pytest # NOQA
2017-01-03 07:24:00 -06:00
sys.exit(pytest.main(args))