haas package

Submodules

haas.error_holder module

class haas.error_holder.ErrorHolder(description)[source]

Bases: object

Placeholder for a TestCase inside a result. As far as a TestResult is concerned, this looks exactly like a unit test. Used to insert arbitrary errors into a test suite run.

countTestCases()[source]
failureException = None
id()[source]
run(result)[source]
shortDescription()[source]

haas.exceptions module

exception haas.exceptions.DotInModuleNameError[source]

Bases: haas.exceptions.HaasException

exception haas.exceptions.HaasException[source]

Bases: exceptions.Exception

exception haas.exceptions.PluginError[source]

Bases: haas.exceptions.HaasException

haas.haas_application module

class haas.haas_application.HaasApplication(argv, **kwargs)[source]

Bases: object

Main haas application entry-point.

run(plugin_manager=None)[source]

Run the haas test runner.

This will load and configure the selected plugins, set up the environment and begin test discovery, loading and running.

Parameters:plugin_manager (haas.plugin_manager.PluginManager) – [Optional] Override the use of the default plugin manager.
haas.haas_application.create_argument_parser()[source]

Creates the argument parser for haas.

haas.loader module

class haas.loader.Loader(test_suite_class=None, test_case_class=None, test_method_prefix=u'test', **kwargs)[source]

Bases: object

Load individual test cases from modules and wrap them in the Suite container.

create_suite(tests=())[source]

Create a test suite using the confugured test suite class.

Parameters:tests (sequence) – Sequence of TestCase instances.
find_test_method_names(testcase)[source]

Return a list of test method names in the provided TestCase subclass.

Parameters:testcase (type) – Subclass of unittest.TestCase
get_test_cases_from_module(module)[source]

Return a list of TestCase subclasses contained in the provided module object.

Parameters:module (module) – A module object containing TestCases
is_test_case(klass)[source]

Check if a class is a TestCase.

load_case(testcase)[source]

Load a TestSuite containing all TestCase instances for all tests in a TestCase subclass.

Parameters:testcase (type) – A subclass of unittest.TestCase
load_module(module)[source]

Create and return a test suite containing all cases loaded from the provided module.

Parameters:module (module) – A module object containing TestCases
load_test(testcase, method_name)[source]

Create and return an instance of unittest.TestCase for the specified unbound test method.

unbound_test : unbound method
An unbound method of a unittest.TestCase

haas.main module

haas.main.main()[source]

Execute haas.

Parameters:argv (list) – The script’s full argument list including the script itself.

haas.module_import_error module

class haas.module_import_error.ModuleImportError[source]

Bases: object

A base class for generated ModuleImportError placeholder test cases.

haas.plugin_context module

class haas.plugin_context.PluginContext(hooks=None, **kwargs)[source]

Bases: object

Handles correct setup and teardown of multiple plugins.

setup()[source]
teardown()[source]

haas.plugin_manager module

class haas.plugin_manager.PluginManager[source]

Bases: object

ENVIRONMENT_HOOK = u'haas.hooks.environment'
RESULT_HANDLERS = u'haas.result.handler'
TEST_DISCOVERY = u'haas.discovery'
TEST_RUNNER = u'haas.runner'
add_plugin_arguments(parser)[source]

Add plugin arguments to argument parser.

Parameters:parser (argparse.ArgumentParser) – The main haas ArgumentParser.
get_driver(namespace, parsed_args, **kwargs)[source]

Get mutually-exlusive plugin for plugin namespace.

get_enabled_hook_plugins(hook, args, **kwargs)[source]

Get enabled plugins for specified hook name.

classmethod testing_plugin_manager(hook_managers, driver_managers)[source]

Create a fabricated plugin manager for testing.

haas.result module

class haas.result.ResultCollecter(*args, **kwargs)[source]

Bases: haas.result.ResultCollector

class haas.result.ResultCollector(buffer=False, failfast=False)[source]

Bases: object

Collecter for test results. This handles creating TestResult instances and handing them off the registered result output handlers.

addError(*args, **kw)[source]

Register that a test ended in an error.

Parameters:
  • test (unittest.TestCase) – The test that has completed.
  • exception (tuple) – exc_info tuple (type, value, traceback).
addExpectedFailure(test, exception)[source]

Register that a test that failed and was expected to fail.

Parameters:
  • test (unittest.TestCase) – The test that has completed.
  • exception (tuple) – exc_info tuple (type, value, traceback).
addFailure(*args, **kw)[source]

Register that a test ended with a failure.

Parameters:
  • test (unittest.TestCase) – The test that has completed.
  • exception (tuple) – exc_info tuple (type, value, traceback).
addSkip(test, reason)[source]

Register that a test that was skipped.

Parameters:
  • test (unittest.TestCase) – The test that has completed.
  • reason (str) – The reason the test was skipped.
addSuccess(test)[source]

Register that a test ended in success.

Parameters:test (unittest.TestCase) – The test that has completed.
addUnexpectedSuccess(*args, **kw)[source]

Register a test that passed unexpectedly.

Parameters:test (unittest.TestCase) – The test that has completed.
add_result(result)[source]

Add an already-constructed TestResult to this ResultCollector.

This may be used when collecting results created by other ResultCollectors (e.g. in subprocesses).

add_result_handler(handler)[source]

Register a new result handler.

printErrors()[source]
separator2 = u'----------------------------------------------------------------------'
startTest(test, start_time=None)[source]

Indicate that an individual test is starting.

Parameters:
  • test (unittest.TestCase) – The test that is starting.
  • start_time (datetime) – An internal parameter to allow the parallel test runner to set the actual start time of a test run in a subprocess.
startTestRun()[source]

Indicate that the test run is starting.

stop()[source]

Set the shouldStop flag, used by the test cases to determine if they should terminate early.

stopTest(test)[source]

Indicate that an individual test has completed.

Parameters:test (unittest.TestCase) – The test that has completed.
stopTestRun()[source]

Indicate that the test run has completed.

wasSuccessful()[source]

Return True if the run was successful.

class haas.result.TestCompletionStatus[source]

Bases: enum.Enum

Enumeration to represent the status of a single test.

error = 3

The test encountered an unexpected error.

expected_failure = 5

A test failed as expected

failure = 2

The test failed, but did not encounter an unexpected error.

skipped = 6

A test was skipped

success = 1

The test completed successfully.

unexpected_success = 4

A test marked as expected to fail unexpected passed.

class haas.result.TestDuration(start_time, stop_time=None)[source]

Bases: object

An orderable representation of the duration of an individual test.

as_integer_ratio()[source]
duration
start_time
stop_time
total_seconds
class haas.result.TestResult(test_class, test_method_name, status, duration, exception=None, message=None)[source]

Bases: object

Container object for all information related to the run of a single test. This contains the test itself, the actual status including the reason or error associated with status, along with timing information.

classmethod from_dict(data)[source]

Create a TestResult from a dictionary created by to_dict()

classmethod from_test_case(test_case, status, duration, exception=None, message=None, stdout=None, stderr=None)[source]

Construct a TestResult object from the test and a status.

Parameters:
  • test_case (unittest.TestCase) – The test that this result will represent.
  • status (haas.result.TestCompletionStatus) – The status of the test.
  • exception (tuple) – exc_info tuple (type, value, traceback).
  • message (str) – Optional message associated with the result (e.g. skip reason).
  • stdout (str) – The test stdout if stdout was buffered.
  • stderr (str) – The test stderr if stderr was buffered.
test

The test case instance this result represents.

to_dict()[source]

Serialize the TestResult to a dictionary.

haas.result.failfast(method)[source]

haas.suite module

class haas.suite.TestSuite(tests=())[source]

Bases: object

A TestSuite is a container of test cases and allows executing many test cases while managing the state of the overall suite.

countTestCases()[source]

Return the total number of tests contained in this suite.

run(result, _state=None)[source]

Run all tests in the suite.

Parameters:result (unittest.result.TestResult) –
haas.suite.find_test_cases(suite)[source]

Generate a list of all test cases contained in a test suite.

Parameters:suite (haas.suite.TestSuite) – The test suite from which to generate the test case list.

haas.testing module

haas.utils module

class haas.utils.abstractclassmethod(callable)[source]

Bases: classmethod

A decorator indicating abstract classmethods.

Similar to abstractmethod.

Usage:

class C(metaclass=ABCMeta):

@abstractclassmethod def my_abstract_classmethod(cls, …):

class haas.utils.cd(destdir)[source]

Bases: object

haas.utils.configure_logging(level)[source]
haas.utils.get_module_by_name(name)[source]

Import a module and return the imported module object.

haas.utils.uncamelcase(string, sep=u'_')[source]