Use actual test outcome¶
Replaces assertion expected values with the actual value from the last failed test run.
Failed tests are matched with the python_files, python_classes, and python_functions rules from the pytest configuration that applies to their project root, so custom test names and multi-root projects are supported.
When the actual value contains non-builtin types, BetterPy adds missing imports through its shared Python import helpers. Fully qualified names in the diff—including <class 'package.module.Type'>, constructor calls, and enum members—select the specified module even when other types share the same name. Existing imports are reused when they resolve to the same target at the assertion, including aliased symbol imports and parent modules that re-export the symbol. Shadowed or different-target bindings are not reused. Otherwise, module qualification is retained to avoid redirecting the replacement. If the module name is also shadowed, BetterPy imports it under an unused alias, avoiding names already bound locally or at module level. Unqualified names still require a single import candidate; ambiguous short names are left for you to import explicitly.
How to invoke: ⌥⏎ / Alt+Enter on a failed assertion → "BetterPy: Use actual test outcome"