Python API reference¶
The objects below are exported from testenix and form the public pre-1.0 API. Pre-1.0 releases
may still make documented breaking changes.
Discovery and execution¶
- testenix.discover(paths='.')[source]¶
Discover native tests and fixtures below one or more paths.
Directories are searched recursively for
test_*.py. An explicitly supplied Python file may have any name, which is useful for focused runs. Inside a module,test_*functions and functions decorated with@test(or parameterized with@case(s)) are collected.- Parameters:
paths (str | Path | Iterable[str | Path])
- Return type:
- testenix.run(paths=None, config=None, *, event_sink=None, sharding_policy=None, trusted_manifest=None)[source]¶
Discover and execute a native Testenix suite.
The coordinator is the only component that decides final outcomes. Workers return immutable attempts, which are emitted to a versioned event stream and reduced after execution.
- Parameters:
paths (Sequence[str] | str | None)
config (TestenixConfig | None)
event_sink (EventSink | None)
sharding_policy (ShardingPolicy | None)
trusted_manifest (TrustedCollectionManifest | None)
- Return type:
- async testenix.run_async(paths=None, config=None, *, event_sink=None, sharding_policy=None, trusted_manifest=None)[source]¶
Cancellable embedding facade around the process-oriented coordinator.
- Parameters:
paths (Sequence[str] | str | None)
config (TestenixConfig | None)
event_sink (EventSink | None)
sharding_policy (ShardingPolicy | None)
trusted_manifest (TrustedCollectionManifest | None)
- Return type:
- class testenix.TestenixConfig(paths=('tests',), workers='auto', retries=0, timeout=None, tags=(), json_path=None, junit_path=None, history_path=PosixPath('.testenix/history.sqlite3'), shard_modules=False, manifest_path=None)[source]¶
Validated execution and reporting settings.
Paths are kept relative to the process working directory. This mirrors normal command-line path handling and makes a config object safe to pass to a worker process without retaining hidden project state.
- Parameters:
paths (tuple[str, ...])
workers (int | Literal['auto'])
retries (int)
timeout (float | None)
tags (tuple[str, ...])
json_path (Path | None)
junit_path (Path | None)
history_path (Path | None)
shard_modules (bool)
manifest_path (Path | None)
- with_overrides(**values)[source]¶
Return a validated copy containing command-line overrides.
- Parameters:
values (Any)
- Return type:
- property resolved_workers: int¶
Pre-discovery worker capacity retained for compatibility.
Native execution should prefer
resolve_workers(), which can see the scheduler’s real module/timeout execution units. Explicit integer configuration has identical behavior through both APIs.
- resolve_workers(selected_specs, durations, *, spawn_method='spawn', shardable_paths=frozenset({}))[source]¶
Resolve an adaptive count after discovery and history lookup.
- Parameters:
selected_specs (Sequence[TestSpec])
durations (Mapping[str, float])
spawn_method (SpawnMethod)
shardable_paths (AbstractSet[str])
- Return type:
int
Result contracts¶
- class testenix.RunResult(run_id: 'str', tests: 'tuple[TestResult, ...]', collection_issues: 'tuple[CollectionIssue, ...]', started_at: 'float', finished_at: 'float', workers_used: 'int | None' = None, shardable_paths: 'tuple[str, ...]' = ())[source]¶
- Parameters:
run_id (str)
tests (tuple[TestResult, ...])
collection_issues (tuple[CollectionIssue, ...])
started_at (float)
finished_at (float)
workers_used (int | None)
shardable_paths (tuple[str, ...])
- class testenix.TestResult(test: 'TestSpec', status: 'Status', attempts: 'tuple[AttemptResult, ...]', duration: 'float')[source]¶
- class testenix.TestSpec(id, path, module_name, function_name, display_name, parameters=<factory>, case_id=None, tags=<factory>, skip_reason=None, xfail_reason=None, timeout=None, source_line=None)[source]¶
Serializable description of one concrete test case.
- Parameters:
id (str)
path (str)
module_name (str)
function_name (str)
display_name (str)
parameters (dict[str, Any])
case_id (str | None)
tags (frozenset[str])
skip_reason (str | None)
xfail_reason (str | None)
timeout (float | None)
source_line (int | None)
- class testenix.CollectionResult(items, registry, issues=())[source]¶
Complete collection output, including non-fatal authoring issues.
- Parameters:
items (tuple[CollectedTest, ...])
registry (FixtureRegistry)
issues (tuple[CollectionIssue, ...])
Migration¶
The programmatic API follows the same copy-only transaction as testenix migrate. project_root
defaults to the current directory. Prefer dry_run=True before a validating or publishing call.
from pathlib import Path
from testenix import MigrationOptions, migrate
report = migrate(
MigrationOptions(
framework="auto",
sources=(Path("tests"),),
output=Path("tests_testenix"),
check_only=True,
)
)
assert report.originals_modified is False
- testenix.migrate(options)[source]¶
Analyze, validate, and optionally publish a native Testenix copy.
No branch of this function writes to a source path. A destination is only published by a no-overwrite rename after the source fingerprints have been checked for concurrent changes.
- Parameters:
options (MigrationOptions)
- Return type:
- class testenix.MigrationOptions(framework, sources, output=PosixPath('testenix_migrated'), workers='auto', validation_timeout=300.0, dry_run=False, check_only=False, project_root=None)[source]¶
Validated input for
migrate().- Parameters:
framework (Literal['auto', 'pytest', 'unittest'])
sources (tuple[Path, ...])
output (Path)
workers (int | Literal['auto'])
validation_timeout (float)
dry_run (bool)
check_only (bool)
project_root (Path | None)
- class testenix.MigrationReport(status, mode, framework, project_root, sources, output, source_hashes, generated_files, mappings, diagnostics, baseline, native_serial, native_parallel, originals_modified, published, message, started_at, finished_at)[source]¶
Complete audit record for a migration attempt.
- Parameters:
status (MigrationStatus)
mode (str)
framework (str)
project_root (str)
sources (tuple[str, ...])
output (str)
source_hashes (Mapping[str, str])
generated_files (tuple[str, ...])
mappings (tuple[TestMapping, ...])
diagnostics (tuple[MigrationDiagnostic, ...])
baseline (ValidationSummary | None)
native_serial (ValidationSummary | None)
native_parallel (ValidationSummary | None)
originals_modified (bool)
published (bool)
message (str)
started_at (float)
finished_at (float)
- class testenix.ValidationSummary(runner, tests, passed, failed, errors, skipped, xfailed, xpassed, exit_code, duration, timed_out=False, detail=None, outcomes=<factory>)[source]¶
Framework-neutral outcome counts from one isolated validation run.
- Parameters:
runner (str)
tests (int)
passed (int)
failed (int)
errors (int)
skipped (int)
xfailed (int)
xpassed (int)
exit_code (int)
duration (float)
timed_out (bool)
detail (str | None)
outcomes (Mapping[str, str])
Events¶
- class testenix.Event(event_id, run_id, event_type, timestamp, sequence, schema_version=1, test_id=None, attempt=None, worker_id=None, payload=<factory>)[source]¶
Append-only fact emitted while a run is executing.
- Parameters:
event_id (str)
run_id (str)
event_type (EventType)
timestamp (float)
sequence (int)
schema_version (int)
test_id (str | None)
attempt (int | None)
worker_id (str | None)
payload (dict[str, Any])