Closed lmmx closed 2 months ago
I have never really used snapshots before, and while I can see them be beneficial in some usecases... I am kind of wondering if it is really needed here? It is very early in this project so I am a bit hesitant to introduce tools unless they are clearly needed.
Fair enough, it was helpful to ensure I didn't go off track, I can keep snapshots separately with a uv workspace or something in that case :thinking: Something to think about!
This PR adds snapshot tests that "pin" the exact output of tests, and store it in the test files automatically (broken out of previous PR #9 as requested)
This seemed like a perfect candidate for inline-snapshot, providing both confidence in the results staying the same, and the ability to inspect the outputs. The inline-snapshot plugin helps easily create/review/fix 'snapshotted' values
The snapshots come from an
if "pytest" in sys.modules:
block, which prints the script metadata and the contents of the intermediate script.I used a utility function in
conftest.py
,fmt_output()
, to postprocess this 'log', which I then assigned to the pytest namespace (since you can't use a pytest fixture for this). This could live in the library module but it's not used at runtime so felt unnecessary.The 'preamble' (file name and function name) is stripped of newlines so that it doesn't run over onto a newline and is therefore visually distinct from the code block (which stays unindented thanks to the backticks either side, and is therefore possible to copy and paste into an interpreter)