mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
tests: Use 'pytest_sessionstart'
This is the recommended way to do pre-session configuration in pytest if not using session fixtures [1]. With this, we're able to remove the custom 'test/run.py' script in its entirety and run 'pytest' like everyone else does. We'll do this separately to keep things simple. [1] https://stackoverflow.com/a/12600154/613428 Signed-off-by: Stephen Finucane <stephen@that.guru>
This commit is contained in:
parent
c33ecd1f8f
commit
529c96a3c9
@ -8,7 +8,9 @@
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
import pytest
|
||||
from sphinx.testing.path import path
|
||||
@ -31,3 +33,32 @@ def rootdir():
|
||||
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='backports')
|
||||
ignore(category=ImportWarning, module='pkgutil')
|
||||
ignore(category=ImportWarning, module='pytest_cov')
|
||||
|
||||
|
||||
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)
|
||||
|
29
tests/run.py
29
tests/run.py
@ -9,35 +9,8 @@
|
||||
: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)))
|
||||
import pytest
|
||||
|
||||
# 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\..*')
|
||||
|
||||
# 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)
|
||||
|
||||
import pytest # NOQA
|
||||
sys.exit(pytest.main(sys.argv[1:]))
|
||||
|
Loading…
Reference in New Issue
Block a user