diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 065ab538a28..588a45ab01e 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -15,10 +15,6 @@ import urllib from ConfigParser import SafeConfigParser from json import dumps -import nose.core -import nose.config -import nose.loader -import nose.plugins.manager from paste import httpserver galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) @@ -29,8 +25,6 @@ driver_util.configure_environment() log = driver_util.build_logger() from base.api_util import get_master_api_key, get_user_api_key -from base.nose_util import run -from base.instrument import StructuredTestDataPlugin from base.test_logging import logging_config_file from base.tool_shed_util import parse_tool_panel_config from functional import database_contexts @@ -140,10 +134,6 @@ def generate_config_file( input_filename, output_filename, config_items ): fh.close() -def run_tests( test_config ): - return run( test_config ) - - def __copy_database_template( source, db_path ): """ Copy a 'clean' sqlite template database (from file or URL) to specified @@ -444,12 +434,9 @@ def main(): master_api_key=master_api_key, user_api_key=get_user_api_key(), ) - test_config = nose.config.Config( env=os.environ, ignoreFiles=ignore_files, plugins=nose.plugins.manager.DefaultPluginManager() ) - test_config.plugins.addPlugin( StructuredTestDataPlugin() ) - test_config.configure( sys.argv ) - result = run_tests( test_config ) - success = result.wasSuccessful() - return success + return driver_util.nose_config_and_run( + ignore_files=ignore_files, + ) if testing_migrated_tools or testing_installed_tools: shed_tools_dict = {} diff --git a/test/base/driver_util.py b/test/base/driver_util.py index a0f3a90adfd..073779538d3 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -1,8 +1,17 @@ """Scripts for drivers of Galaxy functional tests.""" -import tempfile -import os import logging +import os +import sys +import tempfile + +import nose.config +import nose.core +import nose.loader +import nose.plugins.manager + +from .nose_util import run +from .instrument import StructuredTestDataPlugin def setup_tool_shed_tmp_dir(): @@ -26,7 +35,36 @@ def build_logger(): return logging.getLogger("test_driver") +def nose_config_and_run( argv=None, env=None, ignore_files=[], plugins=None ): + """Setup a nose context and run tests. + + Tests are specified by argv (defaulting to sys.argv). + """ + if env is None: + env = os.environ + if plugins is None: + plugins = nose.plugins.manager.DefaultPluginManager() + if argv is None: + argv = sys.argv + + test_config = nose.config.Config( + env=os.environ, + ignoreFiles=ignore_files, + plugins=plugins, + ) + + # Add custom plugin to produce JSON data used by planemo. + test_config.plugins.addPlugin( StructuredTestDataPlugin() ) + test_config.configure( argv ) + + result = run( test_config ) + + success = result.wasSuccessful() + return success + + __all__ = [ "configure_environment", - "build_logger" + "build_logger", + "nose_config_and_run", ] diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index ea5da647f16..d2ca5e9022f 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -18,10 +18,6 @@ galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pa sys.path[0:1] = [ os.path.join( galaxy_root, "lib" ), os.path.join( galaxy_root, "test" ) ] from paste import httpserver -import nose.config -import nose.core -import nose.loader -import nose.plugins.manager from base import driver_util driver_util.configure_environment() @@ -36,7 +32,6 @@ from galaxy.app import UniverseApplication as GalaxyUniverseApplication from galaxy.util import asbool from galaxy.web import buildapp as galaxybuildapp -from base import nose_util from functional import database_contexts default_tool_shed_test_host = "localhost" @@ -119,10 +114,6 @@ shed_data_manager_conf_xml_template = ''' ''' -def run_tests( test_config ): - return nose_util.run( test_config ) - - def main(): # ---- Configuration ------------------------------------------------------ tool_shed_test_host = os.environ.get( 'TOOL_SHED_TEST_HOST', default_tool_shed_test_host ) @@ -135,7 +126,6 @@ def main(): tool_shed_test_file_dir = os.environ.get( 'TOOL_SHED_TEST_FILE_DIR', default_tool_shed_test_file_dir ) if not os.path.isabs( tool_shed_test_file_dir ): tool_shed_test_file_dir = tool_shed_test_file_dir - ignore_files = () tool_dependency_dir = os.environ.get( 'TOOL_SHED_TOOL_DEPENDENCY_DIR', None ) use_distributed_object_store = os.environ.get( 'TOOL_SHED_USE_DISTRIBUTED_OBJECT_STORE', False ) if not os.path.isdir( tool_shed_test_tmp_dir ): @@ -422,11 +412,7 @@ def main(): os.environ[ 'GALAXY_TEST_HOST' ] = galaxy_test_host if tool_shed_test_file_dir: os.environ[ 'TOOL_SHED_TEST_FILE_DIR' ] = tool_shed_test_file_dir - test_config = nose.config.Config( env=os.environ, ignoreFiles=ignore_files, plugins=nose.plugins.manager.DefaultPluginManager() ) - test_config.configure( sys.argv ) - # Run the tests. - result = run_tests( test_config ) - success = result.wasSuccessful() + success = driver_util.nose_config_and_run() except: log.exception( "Failure running tests" )