Preserve Regressions and Reproduce CI Checks
Core idea
A regression test records a previously failing behavior as a reproducible input and independent expected outcome. First reproduce the failure, then fix the defect and verify the test passes. Continuous integration (CI) runs agreed checks automatically on changes. Pin the supported runtime and dependencies, record commands, and preserve failing logs rather than declaring success from a partial run.
import unittestdef broken(units): return 1 + units//4def fixed(units): return (units+3)//4def check(fn): class Regression(unittest.TestCase): def test_exact_multiple(self): self.assertEqual(fn(4), 1) return Regression('test_exact_multiple').run().wasSuccessful()print(check(broken), check(fixed))The same test rejects the old behavior and accepts the fix for exactly four units.
Expected output:
False TrueCheck several named cases
import unittestclass Regression(unittest.TestCase): def test_boxes(self): for units, expected in [(0,0),(4,1),(5,2)]: with self.subTest(units=units): self.assertEqual((units+3)//4, expected)r = Regression('test_boxes').run()print(r.testsRun, r.wasSuccessful())Subtests identify each input if it fails; testsRun counts the enclosing method, not the number of subtests.
Expected output:
1 TrueCommon mistake
Do not rely on a CI badge alone or hide failing checks behind unconditional success. A local run is not a hosted CI run; reproduce the same commands in a clean environment and retain configuration and logs.
Practice
Create test_regression.py with the exact-multiple case and run python -m unittest discover -v locally. Record the runtime, command and exit code. Configure your CI to execute the same command in a supported version matrix; verify the hosted logs separately.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Regression and CI
Check your understanding of regression and ci.
What is printed?
def old(n):return 1+n//4print(old(4))What is printed?
import unittestclass T(unittest.TestCase): def test_a(self):self.assertEqual((4+3)//4,1)print(T("test_a").run().wasSuccessful())What should a regression test retain?
What distinguishes local testing from hosted CI evidence?