Skip to content

Results, configuration, and reference

Run tests from the application root, where reactor lives. All cases must extend TestCase, imported with from orionis.test import TestCase; see creation and dependency injection to prepare the first one.

Both entry points execute the same command:

Terminal window
orionis test
python -B reactor test

With uv, use uv run python -B reactor test. The command starts the application and resolves its registered testing engine. Running python -m unittest directly skips that startup: TestCase methods that delegate to the application require it to be initialized already.

Inspect the options installed in your project:

Terminal window
orionis test --help
python -B reactor test --help

The command has no positional arguments. All these options are optional:

OptionValue and effect
--verbosity N, -v NInteger 0, 1, or 2. Overrides testing.verbosity; configured default: 2.
--fail-fast N, -f NInteger: 1 stops at the first failure or error; 0 continues. Overrides testing.fail_fast, including with 0. Configured default: False.
--start-dir PATH, -s PATHDiscovery directory or Python file. Configured default: tests.
--file-pattern PATTERNFilename glob, initially test_*.py.
--method-pattern PATTERNGlob filtering discovered methods, initially test*.
--panelEnables the start and summary panels; the CLI default.
--no-panelDisables start and summary panels and prevents clearing the console. Does not change per-result verbosity.
--help, -hShows help without executing tests.

--fail-fast requires a value: write --fail-fast 1, rather than only --fail-fast. Although the parser accepts other integers, only 1 enables this CLI option; use 0 or 1. Verbosity outside 0, 1, and 2 raises ValueError.

Terminal window
# Select a directory and a family of cases.
python -B reactor test --start-dir tests/unit --file-pattern "test_invoice*.py" --method-pattern "testCalculate*"
# Stop at the first failed or errored result.
orionis test --fail-fast 1 --verbosity 2
# Continue even when general configuration enables fail-fast.
python -B reactor test --fail-fast 0 --no-panel --verbosity 1

The engine walks the starting directory and subdirectories, even without __init__.py, in sorted order. An explicit .py file selects only that module and bypasses the filename glob. Files must be importable from the application root.

Patterns are globs, such as test_user*.py, testCreate*, or check*, rather than regular expressions. The engine’s loader uses the method glob directly, so --method-pattern 'check*' can select methods with that prefix. Use conventional test... names unless a custom prefix is intentional.

A relative start_dir resolves from the application’s root. The resolved path must exist within that root and must be a directory or a Python file. Missing paths and filesystem traversal errors propagate. A module already imported from another root raises ImportError; use separate processes for projects with overlapping module names.

Filters matching nothing produce an empty suite. The CLI reports that no tests ran and returns 1; an empty execution is not a passing validation. Import failures represented by the loader remain errors even when the method filter does not match. Other discovery exceptions propagate and may prevent a per-case report.

config/testing.py defines BootstrapTesting(Testing), an immutable configuration with keyword-only arguments. Its six properties can be set in that file or through the environment variables it already reads:

PropertyType and defaultEnvironment variable
verbosityint | VerbosityMode, VerbosityMode.DETAILED → 2TESTING_VERBOSITY
fail_fastbool, FalseTESTING_FAIL_FAST
start_dirstr, "tests"TESTING_START_DIR
file_patternstr, "test_*.py"TESTING_FILE_PATTERN
method_patternstr, "test*"TESTING_METHOD_PATTERN
cache_resultsbool, FalseTESTING_CACHE_RESULTS

For example, in .env:

TESTING_VERBOSITY=int:1
TESTING_FAIL_FAST=bool:false
TESTING_START_DIR=tests
TESTING_FILE_PATTERN=test_*.py
TESTING_METHOD_PATTERN=test*
TESTING_CACHE_RESULTS=bool:true

The prefixes produce actual types when configuration is constructed. Use Env in configuration files; at runtime, read these values through IApplication.config(). See Environment to configure loading and persistence.

To fix options directly in config/testing.py, retain the class and replace the appropriate fields:

from dataclasses import dataclass
from orionis.foundation.config.testing import Testing, VerbosityMode
@dataclass(frozen=True, kw_only=True)
class BootstrapTesting(Testing):
verbosity: int | VerbosityMode = VerbosityMode.MINIMAL
fail_fast: bool = True
start_dir: str = "tests/unit"
file_pattern: str = "test_*.py"
method_pattern: str = "test*"
cache_results: bool = True

Testing normalizes VerbosityMode to its integer. Only 0, 1, and 2 are allowed; a boolean is not valid verbosity. fail_fast and cache_results must be actual booleans, rather than 1 or strings. The other three fields must be nonempty strings containing more than whitespace. Invalid types raise TypeError; out-of-range verbosity or blank strings raise ValueError. This validation does not check that the directory exists.

Normal precedence is CLI option → application configuration → engine default. Omitting an option retains configuration; explicit --verbosity 0 and --fail-fast 0 win. An empty CLI string for a directory or pattern falls back to configuration.

The engine supports applications missing individual keys: its fallbacks are 2, False, tests, test_*.py, test*, and False, respectively. Panels are controlled by the CLI or withoutPanel(); Testing has no with_panel field.

ValueEnumPer-result output
0VerbosityMode.SILENTDoes not print each result.
1VerbosityMode.MINIMALCompact line with status, identifier, and duration. Long names may be visually truncated.
2VerbosityMode.DETAILEDPanel with name, class, method, module, and file. Failures and errors add the exception, message, and available source context.

Outer panels are independent: startup shows the date, PID, and loop information; the summary shows totals by status and duration. --verbosity 0 retains both unless you also supply --no-panel.

Terminal window
# No runner presentation; tests can still print their own output.
python -B reactor test --verbosity 0 --no-panel
# One line per result, without clearing the terminal or showing outer panels.
python -B reactor test --verbosity 1 --no-panel

--no-panel does not disable individual verbosity-2 panels. The command does not expose flags for stdout capture, parallel execution, coverage, or JSON on standard output.

TestStatus is a string enum:

StatusMeaning
PASSEDThe case completed without a failure or error.
FAILEDAn assertion failed. Includes an unexpected success marked with expectedFailure.
ERROREDAn exception other than an assertion failure occurred.
SKIPPEDSkipped case or expected failure.

The CLI returns 1 for an empty result list or any FAILED or ERRORED result, and 0 for nonempty results without failures or errors. Skips remain SKIPPED, not passes. Preserve the code in continuous integration. Fail-fast stops subsequent cases after a failure, error, or unexpected success, including failing subtests; it does not skip case cleanup.

A failing subtest exports its identity with subTest() parameters. Successful subtests do not generate separate entries. Totals count recorded outcomes and can differ from the method count when several subtests fail or additional lifecycle errors occur.

Enable cache_results=True in configuration or TESTING_CACHE_RESULTS=bool:true in .env, then run normally:

Terminal window
python -B reactor test --verbosity 1 --no-panel

The engine creates the directory and writes a JSON list at:

storage/framework/cache/testing/<timestamp-in-seconds>-<uuid>.json

Its actual base is app.path("storage_framework"); customizing that path changes the destination. There is no --json option: JSON is a file independent of console presentation. It is saved after the runner, including failed results or an empty list. An exception preventing discovery or the runner from completing can prevent that write; file-writing errors propagate.

Example structure for a successful result; identifiers, paths, and durations vary by run:

[
{
"id": 123456,
"name": "tests.unit.test_totals.TotalTest.testTotal",
"status": "PASSED",
"execution_time": 0.002,
"error_message": null,
"traceback": null,
"class_name": "TotalTest",
"method": "testTotal",
"module": "tests.unit.test_totals",
"file_path": "/srv/project/tests/unit/test_totals.py",
"doc_string": null,
"exception": null,
"line_no": null,
"source_code": []
}
]

Each entry corresponds to an immutable TestResult:

FieldContent
idPython identity of the case or subtest object during that run; not persistent.
nameFull test.id() or subtest name; useful for comparing reports.
statusOne of the four TestStatus strings.
execution_timeSeconds from case startup until recording the outcome.
error_messageException text, or None.
tracebackList of formatted traceback fragments, or None.
class_name, method, moduleCase metadata.
file_pathClass source file when inspectable, or None.
doc_stringMethod docstring, or None.
exceptionException class name, or None.
line_noLine associated with detected error context, or None.
source_code(line_number, code) pairs; two-element lists in JSON. May be empty.

The first four fields are required when constructing TestResult; the others accept None. The processor uses [] when it extracts no code. toDict() returns the representation used by the engine. An ordinary skip does not retain its reason in a separate field; an expected failure preserves diagnostics despite exporting SKIPPED.

Filenames combine the timestamp with a unique identifier, so runs in the same second retain separate reports. There is no automatic retention or filename selector. These files do not prevent tests from running again. With compiled configuration, follow application caching to update it.

Within an initialized application, resolve the contract and configure execution:

from orionis.foundation.contracts.application import IApplication
from orionis.test.contracts.engine import ITestingEngine
from orionis.test.entities.result import TestResult
async def run_selected_tests(app: IApplication) -> list[TestResult]:
engine = await app.make(ITestingEngine)
engine.setStartDir("tests/unit")
engine.setFilePattern("test_*.py")
engine.setMethodPattern("testCalculate*")
engine.setVerbosity(0)
engine.setFailFast(fail_fast=True)
engine.withoutPanel()
return await engine.run()

You can also declare engine: ITestingEngine as a parameter of a container-invoked component. Import the facade from orionis.support.facades; after resolving that service, its instance is pinned:

from orionis.support.facades import Test
async def run_unit_suite():
engine = await Test.resolve()
engine.setStartDir("tests/unit").setVerbosity(1).withoutPanel()
return await Test.run()

The provider registers ITestingEngine → TestingEngine as a deferred singleton and pins the facade instance when starting that service. Explicit resolution allows synchronous configuration without depending on whether the facade was already pinned. Do not recursively execute a suite from a test included in that suite.

Actual signatureOperation
setVerbosity(verbosity: int) -> SelfPresentation level. Use 0, 1, or 2; the setter does not validate the range like the CLI does.
setFailFast(*, fail_fast: bool) -> SelfFirst-failure stopping; keyword-only argument.
setStartDir(start_dir: str) -> SelfDiscovery directory.
setFilePattern(file_pattern: str) -> SelfFilename glob.
setMethodPattern(method_pattern: str) -> SelfMethod glob and TestCase context-local pattern.
withoutPanel() -> SelfDisables startup and summary. The contract has no inverse setter.
discover() -> unittest.TestSuiteNew suite, without execution or JSON.
async run() -> list[TestResult]Discovers, executes, saves JSON when enabled, and returns outcomes.

TestingEngine(app: IApplication) reads configuration and paths at construction. Setters return the same instance and retain changes: subsequent in-process runs inherit them. run() moves the runner to a thread to avoid blocking the caller’s loop; it does not run cases in parallel. Each TestCase has an isolated loop; databases and services need their own isolation strategy.

Normally use the CLI or ITestingEngine. For an integration with an already initialized application, the runner exposes:

TestRunner(
verbosity: int = 0,
failfast: bool = False,
buffer: bool = False,
warnings: str | None = None,
with_panel: bool = True,
**kwargs: dict,
)

run(test: unittest.suite.TestSuite) -> unittest.result.TestResult executes a prepared suite and returns TestResultProcessor by default. It does not discover tests or write JSON. buffer controls standard capture during cases; warnings controls the warning filter. Additional arguments pass through to unittest.TextTestRunner, including stream, descriptions, tb_locals, and durations. Rich uses its own console: stream alone does not redirect its panels. Orionis summaries do not add a duration ranking.

TestResultProcessor(stream=None, descriptions=None, verbosity=None, **kwargs) retains outcomes and exposes getTestResults() -> list[TestResult]. It integrates with unittest callbacks:

CallbackOrionis behavior
startTest(test)Starts case timing.
stopTest(test)Clears active case timing.
addSuccess(test)Records and prints PASSED.
addFailure(test, err)Records FAILED with diagnostics.
addError(test, err)Records ERRORED with diagnostics.
addSkip(test, reason)Records SKIPPED.
addSubTest(test, subtest, err)Adds a result on failure; retains parameterized identity.
addExpectedFailure(test, err)Exports SKIPPED with the expected exception.
addUnexpectedSuccess(test)Exports FAILED with an explanatory AssertionError.

The runner calls startTestRun() and guarantees stopTestRun() through finally when that protocol is available. Ordinary case exceptions become results; an exception from the suite object itself can propagate. Processor storage is per-instance, and getTestResults() returns its list rather than a copy.

Class fixture errors and skips are recorded even before the first case starts. An outcome outside an active test has execution_time=0; it retains available exception diagnostics. Source locations come from the supplied traceback, including when recording happens after the exception handler has finished.

Continue with cases and decorators, or return to Tests.