API Reference#
The virtuous test runner.
virtue.loaders
#
Loaders take a named test case and load the test appropriately.
- class virtue.loaders.AttributeLoader(cls: type, attribute: str)[source]#
I load a test case by instantiating a class with a given attribute name.
This is the typical way that
unittest.TestCase
methods are loaded: by callingTestCase("test_something")
(and then by callingrun()
on the resulting instance to run the selected test method).
- class virtue.loaders.ModuleLoader(locator: ObjectLocator, module: twisted.python.modules.PythonModule)[source]#
I load a test case by locating tests in the module with the given name.
- locator: ObjectLocator#
virtue.locators
#
Loaders find tests which are referenced by names, preparing them for running.
- virtue.locators.prefixed_by(prefix)[source]#
Make a callable returning True for names starting with the given prefix.
The returned callable takes two arguments, the attribute or name of the object, and possibly its corresponding value (which is ignored), as suitable for use with
ObjectLocator.is_test_module
andObjectLocator.is_test_method
.
- virtue.locators.inherits_from_TestCase(attr, cls)[source]#
Return true if a class inherits from
unittest.TestCase
.
- class virtue.locators.ObjectLocator(is_test_method=<function prefixed_by.<locals>.prefixed_by_>, is_test_class=<function inherits_from_TestCase>, is_test_module=<function prefixed_by.<locals>.prefixed_by_>)[source]#
I locate test cases on an object: a package, module or test class.
- Parameters:
is_test_method (collections.abc.Callable) – decide whether the provided object is a test method or not. By default, callable objects whose names (
__name__``s) start with ``test_
are considered test methods.is_test_class (collections.abc.Callable) – decide whether the provided object is a test class or not. By default, objects inheriting from
unittest.TestCase
are considered test cases.is_test_module (collections.abc.Callable) – decide whether the provided object is a test module or not. By default, modules whose names start with
test_
are considered to be test modules.
- is_test_method#
Whether an object is a test method or not
- is_test_class#
Whether an object is a test class or not
- is_test_module#
Whether an object is a test module or not
- locate_by_name(name)[source]#
Locate any tests found in the object referred to by the given name.
The name should be a fully qualified object name. (E.g., the fully qualified object name of this function is
virtue.locators.ObjectLocator.locate_by_name
).A path may also alternatively used, but no
PYTHONPATH
modification will be done, so the file must be importable without modification.
virtue.reporters
#
Outputting and reporting for virtuous test runs.
- class virtue.reporters.Outputter(colored=True, indent=' ', line_width=120)[source]#
An outputter converts test results to renderable strings.
- FAILED = 'FAILED'#
- PASSED = 'PASSED'#
- ERROR = '[ERROR]'#
- FAIL = '[FAIL]'#
- OK = '[OK]'#
- SKIPPED = '[SKIPPED]'#
- EXPECTED_FAILURE = '[XFAIL]'#
- UNEXPECTED_SUCCESS = '[UNEXPECTED SUCCESS]'#
- class virtue.reporters.Counter(errors: int = 0, failures: int = 0, expected_failures: int = 0, unexpected_successes: int = 0, successes: int = 0, subtest_successes: int = 0, subtest_failures: int = 0, subtest_errors: int = 0)[source]#
A counter is a recorder that does not hold references to tests it sees.
- shouldStop = False#
- property count#
Return a total count of all tests.
- property testsRun#
Return a total count of all tests.
- class virtue.reporters.Recorder(errors: PVector = pvector([]), failures: PVector = pvector([]), skips: PVector = pvector([]), successes: PVector = pvector([]), expected_failures: PVector = pvector([]), unexpected_successes: PVector = pvector([]), subtest_successes: PMap = pmap({}), subtest_failures: PMap = pmap({}), subtest_errors: PMap = pmap({}))[source]#
Record test results for later inspection.
- shouldStop = False#
- property testsRun#
- property subtests#
- class virtue.reporters.ComponentizedReporter(outputter: ~virtue.reporters.Outputter = _Nothing.NOTHING, recorder=_Nothing.NOTHING, stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, time=<built-in function time>)[source]#
Combine together outputting and recording capabilities.
- failfast = False#
- shouldStop = False#
- property testsRun#
virtue.runner
#
Runners execute loaded tests.
- virtue.runner.run(tests=(), reporter=None, stop_after=None)[source]#
Run the tests that are loaded by each of the strings provided.
- Parameters:
tests (collections.abc.Iterable) – the collection of tests (specified as
str
s) to runreporter (twisted.trial.itrial.IReporter) – a reporter to use for the run. If unprovided, the default is to return a
virtue.reporters.Counter
(which produces no output).stop_after (int) – a number of non-successful tests to allow before stopping the run.