
- Create a small Python project: a Unit Converter module.
- Use an LLM-based code assistant to produce a robust pytest suite (
test_converter.py). - Run tests (expected to fail initially because
converter.pyis missing). - Implement
converter.pyto satisfy tests. - Iterate until all tests pass; investigate any precision failures and decide whether to change constants, test tolerances, or implementation rounding.
- Virtual environment active (Python 3).
- File
test_converter.pycreated by an LLM from a detailed prompt (implementation intentionally omitted).
- With only
test_converter.pypresent (noconverter.py), pytest fails at collection:
converter.py
Requirements for each function:
- Validate input is numeric (int or float). If not, raise
TypeError. - Return the converted value as a float.
- Prefer well-known constants for conversions to avoid unnecessary precision disagreements.
Recommended implementation (clean, precise)
- After implementing
converter.py, run:
- In the demo workflow this produced 39 passing tests and 1 failure. The failing test revealed a small precision mismatch in the gallons-to-liters expectation:
- LLMs are excellent at producing tests and starter code, but they can trigger small regression cycles: you tweak a constant or rounding to satisfy one test and then break another test. These oscillations require human decisions:
- Should the implementation use a specific authoritative constant?
- Is the test tolerance too strict (adjust pytest.approx)?
- Is rounding required for business logic?
Note: numerical conversions depend on chosen constants and tolerances. Prefer matching documented constants and using
pytest.approx() in tests with a reasonable tolerance. Avoid introducing ad-hoc conditional logic in the implementation to satisfy a single test.- Use an LLM-based assistant to accelerate test generation from a clear, precise prompt.
- Run tests locally as part of the TDD loop: write (or generate) tests, run them, implement the minimal code to pass, iterate.
- For floating point comparisons:
- Use authoritative physical constants where available.
- Use
pytest.approx()with an appropriate tolerance rather than tight equality. - If a business requirement dictates strict rounding, document it and implement rounding explicitly.
- Expect to intervene when the LLM’s automated edits produce regressions—this is part of normal engineering judgment.
- LLM-based tools are powerful for generating tests and scaffolding implementations, but treat their output as a solid starting point, not a final answer.
- Follow core TDD steps:
- Write/generate tests first.
- Run tests and see failures.
- Implement minimally to satisfy tests.
- Iterate until passing, paying attention to numerical precision and test quality.
- Human review is essential for precision, edge cases, and architectural choices.
- pytest documentation: https://docs.pytest.org/en/stable/
- Python packaging and virtual environments: https://packaging.python.org/
- Conversion constants reference (examples): NIST or other authoritative sources