webdriver_test_tools.project.test_loader module

Load test cases from a project.

exception webdriver_test_tools.project.test_loader.TestLoaderException[source]

Bases: Exception

Base exception class for the test_loader module

exception webdriver_test_tools.project.test_loader.TestMethodsNotFoundException[source]

Bases: webdriver_test_tools.project.test_loader.TestLoaderException

Exception raised if no test methods matching the specified criteria were found in a test case class

exception webdriver_test_tools.project.test_loader.TestCasesNotFoundException[source]

Bases: webdriver_test_tools.project.test_loader.TestLoaderException

Exception raised if no test cases matching the specified criteria are found

webdriver_test_tools.project.test_loader.load_project_tests(tests_module, test_module_names=None, skip_module_names=None, test_class_map=None, skip_class_map=None)[source]

Returns a list of WebDriverTestCase subclasses from all submodules in a test project’s tests/ directory

If test_class_map or skip_class_map contain wildcards in any of their keys, those will be expanded into keys for each test class name that matches, altering the original dictionaries as a side effect.

Parameters
  • tests_module – The module object for <test_project>.tests

  • test_module_names – (Optional) List of test module names. Only load test cases from a submodule of tests_module with the given names

  • skip_module_names – (Optional) List of test module names. Do not load test cases from a submodule of tests_module if present in this list

  • test_class_map – (Optional) Dictionary mapping test class names (or wildcard strings) to a list of method names or an empty list if the whole class should be run. Only load test cases that match the keys in this dictionary

  • skip_class_map – (Optional) Dictionary mapping test class names (or wildcard strings) to a list of method names or an empty list if the whole class should be skipped. Skip test cases that match the keys in this dictionary if they’re mapped to an empty list. If one or more methods are specified to skip, it’s possible that there are more methods in the class that should be run

Returns

A list of test classes from all test modules

webdriver_test_tools.project.test_loader.get_test_modules(tests_module, test_module_names=None, skip_module_names=None)[source]

Returns a list of submodules in a test project’s tests/ directory

Parameters
  • tests_module – The module object for <test_project>.tests

  • test_module_names – (Optional) List of test module names. Only load test cases from a submodule of tests_module with the given names

  • skip_module_names – (Optional) List of test module names. Do not load test cases from a submodule of tests_module if present in this list

Returns

A list of test modules

webdriver_test_tools.project.test_loader.get_test_cases(test_module_list)[source]

Returns a list of valid test cases from a list of test modules

Parameters

test_module_list – List of test modules to retrieve test cases from

Returns

List of valid test cases from the test modules

webdriver_test_tools.project.test_loader.expand_wildcard_class_names(test_case_list, test_class_map=None, skip_class_map=None)[source]

Update any entries in test_class_map and skip_class_map with wildcards as keys

Adds keys for each matching class name mapped to the same method lists from the wildcard key, then removes all wildcard keys after expanding

Parameters
  • test_case_list – List of all test cases at this point

  • test_class_map – (Optional) Dictionary mapping test class names (or wildcard strings) to a list of method names or an empty list if the whole class should be run

  • skip_class_map – (Optional) Dictionary mapping test class names (or wildcard strings) to a list of method names or an empty list if the whole class should be skipped

Returns

The modified test_class_map and skip_class_map as a tuple. Either map may be set to None if expanding wildcards caused the map to be empty (i.e. it was all wildcards and none of them matched any test cases)

Raises

TestCasesNotFoundException – if test_class_map was not empty before wildcard expansion but is empty after. This is to override the default behavior of running all tests if test_class_map is empty, because presumably the user wanted to only run a specific subset of tests (otherwise test_class_map would have been empty to begin with)

webdriver_test_tools.project.test_loader.filter_test_cases(test_case_list, test_class_map=None, skip_class_map=None)[source]

Returns a list of test cases filtered by –test and –skip arguments

Parameters
  • test_case_list – List of test case classes to filter

  • test_class_map – (Optional) List of test case class names to load. Will load all if unspecified

  • skip_class_map – (Optional) List of test case class names to skip. Will skip none if unspecified

Returns

List of test case classes filtered based on the –test/–skip arguments

webdriver_test_tools.project.test_loader.load_browser_tests(base_class, generated_test_cases, test_methods=None, skip_methods=None)[source]

Load tests from browser test case classes

Parameters
  • base_class – The base test case class that the generated test cases are based on. Used to expand any wildcards in test_methods or skip_methods to valid test methods

  • generated_test_cases – List of generated browser test case classes for a single subclass of WebDriverTestCase

  • test_methods – (Optional) List of test method names (or wildcard strings). If specified, load only these test methods from each browser test case

  • skip_methods – (Optional) List of test method names (or wildcard strings). If specified, do not load these test methods from each browser test case

Returns

A list of loaded tests from the browser test cases

webdriver_test_tools.project.test_loader.expand_wildcard_method_names(loader, base_class, test_methods=None, skip_methods=None)[source]

Update any entries in test_methods and skip_methods with wildcards

Adds list entries for matching methods in base_class, then removes all wildcard entries after expanding. Additionally, any duplicate entries in the list after wildcard expansion will be removed so the same test method isn’t run multiple times

Parameters
  • loaderunittest.TestLoader object. Used to list all test methods from base_class

  • base_class – The base test case class. Used to get a list of all test methods when searching for matches

  • test_methods – (Optional) List of test method names (or wildcard strings) to run

  • skip_methods – (Optional) List of test method names (or wildcard strings) to skip

Returns

The modified test_methods and skip_methods as a tuple. Either of these may be set to None if expanding wildcards caused the list to be empty (i.e. it was all wildcards and none of them matched any test methods)

Raises

TestMethodsNotFoundException – if test_methods was not empty before wildcard expansion but is empty after. This is to override the default behavior of running all test methods if test_methods is empty, because presumably the user wanted to only run a specific subset of tests (otherwise test_methods would have been empty to begin with)