Imported Upstream version 4.7.2
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python2
|
||||
#!/usr/bin/python3
|
||||
|
||||
# Authors:
|
||||
# Petr Viktorin <pviktori@redhat.com>
|
||||
@@ -20,62 +20,70 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""Nose wrapper for running an installed (not in-tree) IPA test suite
|
||||
"""Pytest wrapper for running an installed (not in-tree) IPA test suite
|
||||
|
||||
Any command-line arguments are passed directly to Nose.
|
||||
Note that any relative paths given will be based on the ipatests module's path
|
||||
Any command-line arguments are passed directly to py.test.
|
||||
The current directory is changed to the locaition of the ipatests package,
|
||||
so any relative paths given will be based on the ipatests module's path
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
from os import path
|
||||
import logging
|
||||
import copy
|
||||
import sys
|
||||
|
||||
import nose
|
||||
import pytest
|
||||
|
||||
from ipapython.ipa_log_manager import log_mgr
|
||||
import ipatests
|
||||
from ipatests.beakerlib_plugin import BeakerLibPlugin
|
||||
from ipatests.order_plugin import OrderTests
|
||||
|
||||
cmd = [
|
||||
sys.argv[0],
|
||||
'--with-doctest',
|
||||
'--doctest-tests',
|
||||
'--with-ordered-tests',
|
||||
'--exclude=plugins',
|
||||
'--nologcapture',
|
||||
'--logging-filter=-paramiko',
|
||||
'--where', os.path.dirname(ipatests.__file__),
|
||||
]
|
||||
cmd += sys.argv[1:]
|
||||
# This is set to store --with-xunit report in an accessible place:
|
||||
os.environ['IPATEST_XUNIT_PATH'] = os.path.join(os.getcwd(), 'nosetests.xml')
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(ipatests.__file__))
|
||||
|
||||
|
||||
# This must be set so ipalib.api gets initialized property for tests:
|
||||
os.environ['IPA_UNIT_TEST_MODE'] = 'cli_test'
|
||||
class ArgsManglePlugin(object):
|
||||
"""Modify pytest arguments
|
||||
|
||||
* Add confcutdir if hasn't been set already
|
||||
* Mangle paths to support tests both relative to basedir and ipatests/
|
||||
* Default to ipatests/ if no tests are specified
|
||||
"""
|
||||
def pytest_load_initial_conftests(self, early_config, parser, args):
|
||||
# During initial loading, parser supports only basic options
|
||||
ns = early_config.known_args_namespace
|
||||
if not ns.confcutdir:
|
||||
# add config cut directory to only load fixtures from ipatests/
|
||||
args.insert(0, '--confcutdir={}'.format(HERE))
|
||||
|
||||
if not ns.file_or_dir:
|
||||
# No file or directory found, run all tests
|
||||
args.append(HERE)
|
||||
else:
|
||||
for name in ns.file_or_dir:
|
||||
idx = args.index(name)
|
||||
# split on pytest separator
|
||||
# ipatests/test_ipaplatform/test_importhook.py::test_override
|
||||
filename, sep, suffix = name.partition('::')
|
||||
# a file or directory relative to cwd or already absolute
|
||||
if os.path.exists(filename):
|
||||
continue
|
||||
# a file or directory relative to ipatests package
|
||||
args[idx] = sep.join((os.path.join(HERE, filename), suffix))
|
||||
|
||||
# replace ignores, e.g. "--ignore test_integration" is changed to
|
||||
# "--ignore path/to/ipatests/test_integration"
|
||||
if ns.ignore:
|
||||
for ignore in ns.ignore:
|
||||
idx = args.index(ignore)
|
||||
if os.path.exists(ignore):
|
||||
continue
|
||||
args[idx] = os.path.join(HERE, ignore)
|
||||
|
||||
# rebuild early_config's known args with new args. The known args
|
||||
# are used for initial conftest.py from ipatests, which adds
|
||||
# additional arguments.
|
||||
early_config.known_args_namespace = parser.parse_known_args(
|
||||
args, namespace=copy.copy(early_config.option))
|
||||
|
||||
|
||||
# Forward IPA logging to a normal Python logger. Nose's logcapture plugin
|
||||
# can't work with IPA-managed loggers
|
||||
class LogHandler(logging.Handler):
|
||||
name = 'forwarding log handler'
|
||||
logger = logging.getLogger('IPA')
|
||||
|
||||
def emit(self, record):
|
||||
self.logger.log(record.levelno, self.format(record))
|
||||
|
||||
if 'console' in log_mgr.handlers:
|
||||
log_mgr.remove_handler('console')
|
||||
log_mgr.configure(
|
||||
{
|
||||
'default_level': 'DEBUG',
|
||||
'handlers': [{'log_handler': LogHandler(),
|
||||
'format': '[%(name)s] %(message)s',
|
||||
'level': 'debug'},
|
||||
{'level': 'debug',
|
||||
'name': 'console',
|
||||
'stream': sys.stderr}]},
|
||||
configure_state='tests')
|
||||
|
||||
|
||||
nose.main(argv=cmd, addplugins=[BeakerLibPlugin(), OrderTests()])
|
||||
sys.exit(pytest.main(plugins=[ArgsManglePlugin()]))
|
||||
|
||||
Reference in New Issue
Block a user