Keep inline-snapshot disabled when pytest runs in a terminal - #3634
Conversation
`default-flags = ["disable"]` only covers runs whose stdout is not a terminal. In a terminal outside CI the plugin fell back to its own `default-flags-tui` default (`create`, `review`), stayed active, and the locked version raised `AttributeError: ... has no attribute '_meta'` on every `snapshot(...)` literal that spells the field as `_meta=`. Set `default-flags-tui` to `disable` as well, so a plain `pytest` run behaves the same in a terminal, in a pipe and in CI. Snapshots are still updated with an explicit `--inline-snapshot=create` or `fix`. Fixes #3544
📚 Documentation preview
|
There was a problem hiding this comment.
LGTM, straightforward test-tooling config change.
What was reviewed: the one-line addition of default-flags-tui = ["disable"] under [tool.inline-snapshot] in pyproject.toml, which only affects how the pytest plugin behaves in an interactive terminal; it has no runtime or packaging effect. Checked the lowest-direct CI matrix concern: CI sets CI, which switches the plugin off regardless, and inline-snapshot reads config keys with .get(), so an unrecognised key would be ignored rather than error. The ruled-out candidate (this hides the _meta AttributeError rather than fixing it) is accurate but already stated in the PR description's "What it does not fix" section and is a plugin-version concern outside this change's scope.
Extended reasoning...
The change touches only the [tool.inline-snapshot] table in pyproject.toml, adding a second disable flag so the pytest plugin stays off when stdout is a TTY, matching the existing non-TTY and CI behaviour. It touches no source, tests, lockfile, dependency bounds, or security-sensitive surface. There is no CODEOWNERS file in the repo, the bug hunt ran dry, and the timeline shows no third-party objections. The only investigated candidate (masking rather than fixing the _meta snapshot incompatibility) is openly acknowledged in the PR description and does not make the change incorrect.
Fixes #3544
What was wrong
Running
uv run pytestin a terminal outside CI fails 14 tests intests/client/test_client.pyand 39 in the whole suite, all withAttributeError: '...Result' object has no attribute '_meta'.This is not specific to Windows. It happens on Linux and macOS too, in any terminal where no CI variable is set (Python 3.11 and later; 3.10 passes).
pyproject.tomlsetsdefault-flags = ["disable"]for inline-snapshot, but that key only applies when stdout is not a terminal. In a terminal the plugin readsdefault-flags-tui, which was unset, so it used its own default ofcreate,reviewand stayed active. When active, the locked version (0.28.0) looks up each keyword of asnapshot(...)literal as an attribute, and_metais a field alias rather than an attribute. CI and piped runs never see it because the plugin is off there.What changes
default-flags-tuiis set to["disable"]as well, so a plainpytestrun behaves the same in a terminal, in a pipe and in CI.Updating snapshots on purpose is unchanged:
--inline-snapshot=createand--inline-snapshot=fixstill rewrite ordinary snapshots.What it does not fix
--inline-snapshot=flag other thandisablestill fails on the_meta=snapshots under the locked plugin version. That was already the case and needs a plugin upgrade, which is not part of this change.snapshot()now fails with "run pytest with --inline-snapshot=create" instead of being filled in, and a stale snapshot is an ordinary assertion failure instead of a y/n prompt at the end of the run. Piped runs already behaved this way.Why there is no regression test
The plugin switches itself off when
CIis set, so a test for this would pass in CI with or without the fix.How it was checked
All runs had the CI variables unset, and the terminal runs confirmed
sys.stdout.isatty()is true in the pytest process.tests/client/test_client.py, pipedtests/client/test_client.py, pseudo-terminal--inline-snapshot=createandfixon a scratch testThe same before and after (14 failures to none, 39 to none) was seen on GitHub-hosted Windows, Ubuntu and macOS runners under a pseudo-terminal.
ruff,pyrightand./scripts/testpass.AI Disclaimer