Reporters are in charge of handling the state and outcome of test-runs. They might output machine- or human-readable reports on the console, or display the results in a graphical user interface.
Get an AbstractReporter by name, falling back on a default.
Reporters are registered via setuptools entry points, in the 'attest.reporters' group. A third-party reporter can thus register itself using this in its setup.py:
setup(
entry_points = {
'attest.reporters': [
'name = import.path.to:callable'
]
}
)
Names for the built in reporters:
Parameters: |
|
---|---|
Raises KeyError: | |
If neither the name or the default is a valid name of a reporter. |
|
Return type: | Callable returning an instance of an AbstractReporter. |
Changed in version 0.4: Reporters are registered via setuptools entry points.
Iterable yielding the names of all registered reporters.
>>> list(get_all_reporters())
['xml', 'plain', 'quickfix', 'fancy', 'auto']
New in version 0.4.
Select a reporter based on the target output and installed dependencies.
This is the default reporter.
Parameters: | opts – Passed to FancyReporter if it is used. |
---|---|
Return type: | FancyReporter if output is a terminal and the progressbar and pygments packages are installed, otherwise a PlainReporter. |
Changed in version 0.5: A test_loader function attribute similar to AbstractReporter.test_loader().
Heavily uses ANSI escape codes for fancy output to 256-color terminals. Progress of running the tests is indicated by a progressbar and failures are shown with syntax highlighted tracebacks.
Parameters: |
|
---|
Styles
Available styles can be listed with pygmentize -L styles. The special values 'light' and 'dark' (referring to the terminal’s background) use the 16 system colors rather than assuming a 256-color terminal.
Defaults to light or the environment variable ATTEST_PYGMENTS_STYLE.
Changed in version 0.6: Added the 16-color styles light and dark and the complementary colorscheme option
This is known to work with Vim, but can probably be used with other editors as well. The output mimics that used by many compilers for errors and warnings.
Report failures in a format that’s understood by Vim’s quickfix feature.
Write a Makefile that runs your tests with this reporter and then from Vim you can do :mak. If there’s failures, Vim will jump to the first one by opening the offending file and positioning the cursor at the relevant line; you can jump between failures with :cn and :cp. For more information try :help quickfix.
Example Makefile (remember to indent with tabs not spaces):
test:
@python runtests.py -rquickfix
New in version 0.5.
Optional base for reporters, serves as documentation and improves errors for incomplete reporters.
Creates a basic unittest test loader using this reporter. This can be used to run tests via distribute, for example:
setup(
test_loader='attest:FancyReporter.test_loader',
test_suite='tests.collection',
)
Now, python setup.py -q test is equivalent to:
from attest import FancyReporter
from tests import collection
collection.run(FancyReporter)
If you want to run the tests as a normal unittest suite, try test_suite() instead:
setup(
test_suite='tests.collection.test_suite'
)
New in version 0.5.
Called when a test run has begun.
Parameters: | tests – The list of test functions we will be running. |
---|
Called when a test succeeds.
Parameters: | result (TestResult) – Result data for the succeeding test. |
---|
Changed in version 0.4: Parameters changed to result.
Called when a test fails.
Parameters: | result (TestResult) – Result data for the failing test. |
---|
Changed in version 0.4: Parameters changed to result.
Container for result data from running a test.
New in version 0.4.
The exception instance, if the test failed.
The exc_info() of the exception, if the test failed.
Like traceback.extract_tb() with uninteresting entries removed.
New in version 0.5.
A list of lines the test printed on the standard error.
A list of lines the test printed on the standard output.
The test callable.