# ruff UP005: fix changes program behavior

Internal evidence sheet generated by fixhunt. Not an issue text. A human re-verifies, checks the duplicates
below, and writes the upstream report in their own words following the project's AI policy.

- Tool: ruff ruff 0.17.1
- Rule: UP005 (tool labels the fix: unknown, this fix reported as safe)
- Oracle: fix-changes-behavior
- Judge (Nemotron 3 Ultra, advisory): program-bug, severity high. The original program already fails with an AttributeError because 'assertAlmostEquals' does not exist on the TestCase class in the execution environment (likely Python 3.12+ where the alias was removed). The fix correctly rewrites it to 'assertAlmostEqual', but the program then fails with a NameError due to the undefined variable 'val', which is a pre-existing bug unrelated to the rewrite.
- Program: minimized from 12 to 8 lines

## Reproducer

```python
import unittest
class Test(unittest.TestCase):
    def test(self):
        try:
            self.assertAlmostEquals(val, 0.333, places=5)
        except AssertionError as e:
            print('AssertionError:', type(e).__name__, str(e))
Test().test()
```

## Commands

```sh
python3 prog.py
ruff check --preview --isolated --select UP005 --fix prog.py
python3 prog.py
```

## Observed

```
stderr before: AttributeError: 'Test' object has no attribute 'assertAlmostEquals'. Did you mean: 'assertAlmostEqual'?
stderr after: NameError: name 'val' is not defined. Did you mean: 'eval'?
```

## Diff applied by the fix

```diff
--- orig.py	2026-10-22 13:38:35.581222571 -0400
+++ fixed.py	2026-10-22 13:38:38.682275047 -0400
@@ -2,7 +2,7 @@
 class Test(unittest.TestCase):
     def test(self):
         try:
-            self.assertAlmostEquals(val, 0.333, places=5)
+            self.assertAlmostEqual(val, 0.333, places=5)
         except AssertionError as e:
             print('AssertionError:', type(e).__name__, str(e))
 Test().test()
```

## Why the rewrite is not equivalent (model draft, verify before use)

The original call to assertAlmostEquals raises an AttributeError because that method does not exist on unittest.TestCase; this exception is caught and printed. After rewriting to assertAlmostEqual, which exists, execution proceeds but fails when evaluating val, raising an uncaught NameError since val is undefined. Thus the fix changes which exception occurs and whether it is handled, altering program behavior.

## Upstream search

Queries: "UP005 fix", "UP005 assertAlmostEquals method call", "unittest assertion method rename behavior", "AttributeError to NameError transition in tests"

- no duplicate or related report found among 6 hits

<details><summary>All hits</summary>

- [github, closed] unused-function-argument not silenced by prefixed underscore if variable name is "次" — https://github.com/astral-sh/ruff/issues/28721
- [github, closed] Formatter: Bug with Pragma Comment for pyright being moved to invalid position — https://github.com/astral-sh/ruff/issues/8481
- [github, closed] Fixed code unformatted — https://github.com/astral-sh/ruff/issues/8619
- [github, closed] Add option to disable preview warnings — https://github.com/astral-sh/ruff/issues/8620
- [github, closed] Implement pyupgrade — https://github.com/astral-sh/ruff/issues/827
- [github, closed] Implement autoformat capabilities — https://github.com/astral-sh/ruff/issues/1904

</details>
