summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.appveyor.yml2
-rw-r--r--.circleci/config.yml2
-rw-r--r--CONTRIBUTING.rst19
-rw-r--r--Makefile4
-rw-r--r--tests/conftest.py34
-rwxr-xr-xtests/run.py59
-rw-r--r--tests/test_pycode.py3
-rw-r--r--tox.ini4
8 files changed, 55 insertions, 72 deletions
diff --git a/.appveyor.yml b/.appveyor.yml
index a3f83394f..d2c5d0d95 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -39,7 +39,7 @@ test_script:
if (-not $test_ignore) { $test_ignore = '' }
$tests = $env:TEST
if (-not $tests) { $tests = '' }
- & "C:\Python$($env:PYTHON)\python.exe" run.py $test_ignore.Split(' ') --junitxml .junit.xml $tests.Split(' ')
+ & "C:\Python$($env:PYTHON)\python.exe" -m pytest $test_ignore.Split(' ') --junitxml .junit.xml $tests.Split(' ')
Pop-Location
if ($LastExitCode -eq 1) { Write-Host "Test Failures Occurred, leaving for test result parsing" }
elseif ($LastExitCode -ne 0) { Write-Host "Other Error Occurred, aborting"; exit $LastExitCode }
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 1bbcb4884..f4d4415f1 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -6,4 +6,6 @@ jobs:
working_directory: /sphinx
steps:
- checkout
+ - run: /python3.4/bin/pip install -U pip setuptools
+ - run: /python3.4/bin/pip install -U .[test,websupport]
- run: make test PYTHON=/python3.4/bin/python
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index c4b8569b0..03d26c001 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -317,14 +317,17 @@ There are a couple reasons that code in Sphinx might be deprecated:
no longer needs to support the older version of Python that doesn't include
the library, the library will be deprecated in Sphinx.
-As the :ref:`deprecation-policy` describes,
-the first release of Sphinx that deprecates a feature (``A.B``) should raise a
-``RemovedInSphinxXXWarning`` (where XX is the Sphinx version where the feature
-will be removed) when the deprecated feature is invoked. Assuming we have good
-test coverage, these warnings are converted to errors when running the test
-suite with warnings enabled: ``python -Wall tests/run.py``. Thus, when adding
-a ``RemovedInSphinxXXWarning`` you need to eliminate or silence any warnings
-generated when running the tests.
+As the :ref:`deprecation-policy` describes, the first release of Sphinx that
+deprecates a feature (``A.B``) should raise a ``RemovedInSphinxXXWarning``
+(where ``XX`` is the Sphinx version where the feature will be removed) when the
+deprecated feature is invoked. Assuming we have good test coverage, these
+warnings are converted to errors when running the test suite with warnings
+enabled::
+
+ pytest -Wall
+
+Thus, when adding a ``RemovedInSphinxXXWarning`` you need to eliminate or
+silence any warnings generated when running the tests.
.. _deprecation-policy:
diff --git a/Makefile b/Makefile
index e4abba088..67699363f 100644
--- a/Makefile
+++ b/Makefile
@@ -69,7 +69,7 @@ reindent:
.PHONY: test
test:
- @cd tests; $(PYTHON) run.py -v $(TEST)
+ @$(PYTHON) -m pytest -v $(TEST)
.PHONY: test-async
test-async:
@@ -77,7 +77,7 @@ test-async:
.PHONY: covertest
covertest:
- @cd tests; $(PYTHON) run.py -v --cov=sphinx --junitxml=.junit.xml $(TEST)
+ @$(PYTHON) -m pytest -v --cov=sphinx --junitxml=.junit.xml $(TEST)
.PHONY: build
build:
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'
diff --git a/tox.ini b/tox.ini
index 36fdf83f4..ae6b2a4b3 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,6 +1,7 @@
[tox]
minversion = 2.0
envlist = docs,flake8,mypy,coverage,py{27,34,35,36,py},du{11,12,13,14}
+skipsdist = True
[testenv]
passenv =
@@ -20,9 +21,10 @@ deps =
du13: docutils==0.13.1
du14: docutils==0.14
setenv =
+ PYTHONWARNINGS = all,ignore::ImportWarning:pkgutil
SPHINX_TEST_TEMPDIR = {envdir}/testbuild
commands=
- {envpython} -Wall tests/run.py --durations 25 {posargs}
+ pytest -Wall --durations 25 {posargs}
[testenv:flake8]
description =