Run the application’s failure and integration checks from one command that can also serve as a repository CI job.
Problem
When you need this. A change to arrival-time filtering can leak future events even when fitting still completes. A change to packaging can leave a model that no prediction process can load. The pipeline therefore needs checks for its data and artifact contracts, not just a successful training command.
This workshop runs the earlier tests and the new local platform integration tests from one command. The command returns a machine-readable result and a nonzero exit status when a check fails.
Concepts
Continuous integration runs checks when code changes. It answers whether the change satisfies the checks included in that job. Model evaluation asks how a candidate performs on an intended population; passing unit tests cannot answer that question.
The suite covers strict JSON and event availability, temporal splits, immutable identities, actual MLflow artifacts, Prefect retry behavior, registry selection and prediction validation. Temporary local databases keep one test run from depending on old state.
The lab also includes ci.yml, an optional GitHub Actions workflow for a repository that has the extracted lab at its root. It installs the same pinned environment and calls the same checker. This lesson runs the local command only; the hosted workflow has not run.
Architecture
Working code
Download the shared application and tests, unzip it and enter mlops-return-workflow/. Keep the same directory throughout the course. Create the environment once. Install the pinned platform dependencies for this workshop.
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements-platform.txtOn PowerShell, activate with .venv\Scripts\Activate.ps1.
Continue from Retry a failed step without repeating the experiment; keep the same lab directory and outputs.
Make check results usable by automation
check() loads four test modules, runs them and records the counts. main() writes the result to JSON and exits with status 1 when a test fails or raises an error. The runner prints its verbose text output to stderr, so the names of failed tests stay visible.
def check():
names=['test_workflow','test_foundations','test_tracking','test_platform']
suite=unittest.defaultTestLoader.loadTestsFromNames(names)
stream=io.StringIO();result=unittest.TextTestRunner(stream=stream,verbosity=2).run(suite)
print(stream.getvalue(),file=sys.stderr)
return {'command':'python ci.py','tests_run':result.testsRun,'failures':len(result.failures),
'errors':len(result.errors),'skipped':len(result.skipped),'passed':result.wasSuccessful(),
'python':sys.version.split()[0],'packages':{p:importlib.metadata.version(p) for p in ['mlflow-skinny','prefect']},
'execution':'actual local tests; hosted GitHub Actions job not executed'}def main():
p=argparse.ArgumentParser();p.add_argument('--out',type=Path,required=True);a=p.parse_args()
result=check();w.save(a.out,result);print(json.dumps(result,indent=2));sys.exit(0 if result['passed'] else 1)
if __name__=='__main__':main()python course.py ci-checks --workspace work/course{
"command": "python ci.py",
"tests_run": 55,
"failures": 0,
"errors": 0,
"skipped": 0,
"passed": true,
"python": "3.12.8",
"packages": {
"mlflow-skinny": "3.17.2",
"prefect": "3.9.0"
},
"execution": "actual local tests; hosted GitHub Actions job not executed"
}The result also records the Python version and the installed mlflow-skinny and prefect versions.
Keep independent checks around the integration
The cohort and registry tests break their contracts on purpose. Then they check the effect: no candidate file was written, or the selected registry version did not change. A test that only repeats a function’s return value would not catch these effects.
def ci_report(root):
import ci
need(root,'retry-state.json');result=ci.check()
if not result['passed']:raise ValueError('local CI checks failed; inspect raw test output')
return resultRead the named failure tests in test_platform.py alongside the earlier test_workflow.py and test_foundations.py. The downloaded lab contains all of them.
Recorded commands retain outputs in recorded-platform/; your commands use work/. Read the actual command records. Use a fresh work directory for another attempt.
Failure cases
A green job that never discovers tests is not useful. The saved result includes tests_run, failures, errors and skipped. After you change the module list in check(), compare tests_run with the recorded result before you trust a green job.
Some tests make Prefect and MLflow runs fail on purpose to check their boundaries. Those runs print failure logs even when every test passes. Decide from the final test summary and the exit status, not from individual log lines.
python -m unittest -v test_platform.pyRunning and scaling the workshop
Use python ci.py --out work/ci-result.json to call the checker directly. Put ci.yml under .github/workflows/ only when the lab becomes its own repository.
Keep remote credentials out of this job; it needs none, because it uses synthetic data, local CPU fitting and temporary stores. A larger project can split fast contract tests from slower integration tests, as long as both run before release.
Key takeaways
- CI checks code and contracts; candidate gates check evaluated artifacts.
- A useful job preserves diagnostics and propagates failures.
- A workflow file does not show that a hosted job ran.
Best practices
Test time rules and artifact loading, not only the training return code.
Keep the same entry point for local and repository checks.
Check your understanding
Can passing these tests replace candidate-quality evaluation?
Show the explanation
No. They check program behavior on known cases. The next workshop evaluates the fitted candidate against its declared validation policy.
Read the explanation
Inspect discovered test count, failures, errors, skips and exit status. A zero exit without discovered checks cannot establish that the intended suite ran.