Test suite runner enhancements:

To chase down a set of tests that were failing together, we wanted to run
deeper trees of tests. We changed the behavior of the --pkg argument to
runtests.py so it runs tests under a package and its subpackages, instead
of for a single node.

It gave us more flexibility in what tests to run. This also includes the
--exclude option.

To run tests for a single node, ".tests" can be appended to the package path.

Tira & George.
pull/3/head
Atira Odhner 2017-02-15 15:10:31 +00:00 committed by Dave Page
parent 30a3167c0c
commit b6486f3d42
4 changed files with 62 additions and 63 deletions

View File

@ -54,27 +54,23 @@ class TestsGeneratorRegistry(ABCMeta):
ABCMeta.__init__(cls, name, bases, d) ABCMeta.__init__(cls, name, bases, d)
@classmethod @classmethod
def load_generators(cls, pkg): def load_generators(cls, pkg_root, exclude_pkgs):
cls.registry = dict() cls.registry = dict()
all_modules = []
all_modules += find_modules(pkg_root, False, True)
# Check for SERVER mode # Check for SERVER mode
if config.SERVER_MODE: for module_name in all_modules:
for module_name in find_modules(pkg, False, True): try:
try: if "tests." in str(module_name) and not any(
if "tests." in str(module_name): str(module_name).startswith('pgadmin.' + str(exclude_pkg)) for exclude_pkg in exclude_pkgs
import_module(module_name) ):
except ImportError: import_module(module_name)
traceback.print_exc(file=sys.stderr) except ImportError:
else: traceback.print_exc(file=sys.stderr)
for module_name in find_modules(pkg, False, True):
try:
# Exclude the test cases in browser node if SERVER_MODE
# is False
if "pgadmin.browser.tests" not in module_name:
import_module(module_name)
except ImportError:
traceback.print_exc(file=sys.stderr)
import six import six

View File

@ -115,10 +115,26 @@ Execution:
run 'python runtests.py --pkg all' or just: run 'python runtests.py --pkg all' or just:
'python runtests.py' 'python runtests.py'
- Execute test framework for entire package
Example 1) Run test framework for 'browser' package
run 'python runtests.py --pkg browser'
Example 2) Run test framework for 'database' package
run 'python runtests.py --pkg browser.server_groups.servers.databases'
- Execute test framework for single node at a time - Execute test framework for single node at a time
Example 1) Run test framework for 'browser' node Example 1) Run test framework for 'browser' node
run 'python runtests.py --pkg browser' run 'python runtests.py --pkg browser.tests'
Example 2) Run test framework for 'database' node Example 2) Run test framework for 'database' node
run 'python runtests.py --pkg browser.server_groups.servers.databases' run 'python runtests.py --pkg browser.server_groups.servers.databases.tests'
- Exclude a package and its subpackages when running tests:
Example: exclude acceptance tests but run all others:
run 'python runtests.py --exclude acceptance'
Example: exclude multiple packages:
run 'python runtests.py --exclude browser.server_groups.servers.databases,browser.server_groups.servers.tablespaces'

View File

@ -138,12 +138,20 @@ def get_test_modules(arguments):
from pgadmin.utils.route import TestsGeneratorRegistry from pgadmin.utils.route import TestsGeneratorRegistry
exclude_pkgs = []
if not config.SERVER_MODE:
exclude_pkgs.append("browser.tests")
if arguments['exclude'] is not None:
exclude_pkgs += arguments['exclude'].split(',')
# Load the test modules which are in given package(i.e. in arguments.pkg) # Load the test modules which are in given package(i.e. in arguments.pkg)
if arguments['pkg'] is None or arguments['pkg'] == "all": if arguments['pkg'] is None or arguments['pkg'] == "all":
TestsGeneratorRegistry.load_generators('pgadmin') TestsGeneratorRegistry.load_generators('pgadmin', exclude_pkgs)
else: else:
TestsGeneratorRegistry.load_generators('pgadmin.%s.tests' % TestsGeneratorRegistry.load_generators('pgadmin.%s' %
arguments['pkg']) arguments['pkg'],
exclude_pkgs)
# Sort module list so that test suite executes the test cases sequentially # Sort module list so that test suite executes the test cases sequentially
module_list = TestsGeneratorRegistry.registry.items() module_list = TestsGeneratorRegistry.registry.items()
@ -163,7 +171,9 @@ def add_arguments():
parser = argparse.ArgumentParser(description='Test suite for pgAdmin4') parser = argparse.ArgumentParser(description='Test suite for pgAdmin4')
parser.add_argument('--pkg', help='Executes the test cases of particular' parser.add_argument('--pkg', help='Executes the test cases of particular'
' package') ' package and subpackages')
parser.add_argument('--exclude', help='Skips execution of the test '
'cases of particular package and sub-packages')
arg = parser.parse_args() arg = parser.parse_args()
return arg return arg
@ -268,7 +278,7 @@ if __name__ == '__main__':
print("\n=============Running the test cases for '%s'=============" print("\n=============Running the test cases for '%s'============="
% server['name'], file=sys.stderr) % server['name'], file=sys.stderr)
# Create test server # Create test server
test_utils.create_parent_server_node(server, node_name) test_utils.create_parent_server_node(server)
suite = get_suite(test_module_list, server, test_client) suite = get_suite(test_module_list, server, test_client)
tests = unittest.TextTestRunner(stream=sys.stderr, tests = unittest.TextTestRunner(stream=sys.stderr,
@ -284,7 +294,7 @@ if __name__ == '__main__':
failure = True failure = True
# Delete test server # Delete test server
# test_utils.delete_test_server(test_client) test_utils.delete_test_server(test_client)
except SystemExit: except SystemExit:
drop_objects() drop_objects()

View File

@ -230,53 +230,30 @@ def add_schema_to_parent_node_dict(srv_id, db_id, schema_id, schema_name):
"schema_name": schema_name}) "schema_name": schema_name})
def create_parent_server_node(server_info, node_name): def create_parent_server_node(server_info):
""" """
This function create the test server which will act as parent server, This function create the test server which will act as parent server,
the other node will add under this server the other node will add under this server
:param server_info: server details :param server_info: server details
:type server_info: dict :type server_info: dict
:param node_name: node name
:type node_name: str
:return: None :return: None
""" """
srv_id = create_server(server_info) srv_id = create_server(server_info)
if node_name == "databases": # Create database
# Create test database test_db_name = "test_db_%s" % str(uuid.uuid4())[1:6]
test_db_name = "test_db_%s" % str(uuid.uuid4())[1:6] db_id = create_database(server_info, test_db_name)
db_id = create_database(server_info, test_db_name) add_db_to_parent_node_dict(srv_id, db_id, test_db_name)
add_db_to_parent_node_dict(srv_id, db_id, test_db_name) # Create schema
elif node_name == "schemas": schema_name = "test_schema_%s" % str(uuid.uuid4())[1:6]
test_db_name = "test_db_%s" % str(uuid.uuid4())[1:6] connection = get_db_connection(test_db_name,
db_id = create_database(server_info, test_db_name) server_info['username'],
add_db_to_parent_node_dict(srv_id, db_id, test_db_name) server_info['db_password'],
# Create schema server_info['host'],
schema_name = "test_schema_%s" % str(uuid.uuid4())[1:6] server_info['port'])
connection = get_db_connection(test_db_name,
server_info['username'],
server_info['db_password'],
server_info['host'],
server_info['port'])
schema = regression.schema_utils.create_schema(connection, schema_name) schema = regression.schema_utils.create_schema(connection, schema_name)
add_schema_to_parent_node_dict(srv_id, db_id, schema[0], add_schema_to_parent_node_dict(srv_id, db_id, schema[0],
schema[1]) schema[1])
elif node_name not in ["servers", "roles", "tablespaces", "browser"]:
# Create test database
test_db_name = "test_db_%s" % str(uuid.uuid4())[1:6]
db_id = create_database(server_info, test_db_name)
add_db_to_parent_node_dict(srv_id, db_id, test_db_name)
# Create schema
schema_name = "test_schema_%s" % str(uuid.uuid4())[1:6]
connection = get_db_connection(test_db_name,
server_info['username'],
server_info['db_password'],
server_info['host'],
server_info['port'])
schema = regression.schema_utils.create_schema(connection, schema_name)
add_schema_to_parent_node_dict(srv_id, db_id, schema[0],
schema[1])
def delete_test_server(tester): def delete_test_server(tester):