fixhunt

ruff UP005: fix changes program behavior

fix-changes-behaviorlabelled safeprogram-bug · highno match
Findings / 2026-10-17T21-11-13-477Z-9jdd-ruff-UP005 / r1-p006ruff 0.17.112 → 8 lines2026-10-17 21:11 UTC

Hypothesis Nemotron 3 Super predicted to fire fired 1×

UP005 rewrite occurs in assertAlmostEquals with float division arguments; precision-sensitive output shows if fix alters evaluation timing or value.

Program

before
1import unittest
2class Test(unittest.TestCase):
3 def test(self):
4 try:
5 self.assertAlmostEquals(val, 0.333, places=5)
6 except AssertionError as e:
7 print('AssertionError:', type(e).__name__, str(e))
8Test().test()
after
1import unittest
2class Test(unittest.TestCase):
3 def test(self):
4 try:
5 self.assertAlmostEqual(val, 0.333, places=5)
6 except AssertionError as e:
7 print('AssertionError:', type(e).__name__, str(e))
8Test().test()

Output

stdout beforeexit 1
(no stdout)
AttributeError: 'Test' object has no attribute 'assertAlmostEquals'. Did you mean: 'assertAlmostEqual'?
stdout afterexit 1
(no stdout)
NameError: name 'val' is not defined. Did you mean: 'eval'?
fired
1 before · 0 after
runs
each version twice, same file name, no network

Judge Nemotron 3 Ultra advisory program-bug · 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.

Explanation Nemotron 3 Super unverified

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.

Reproduce

file
prog.py (the before program)
minimized program
r1-p006.py
evidence sheet
r1-p006.md
regression fixture
r1-p006.py the minimized program with a header stating the observed change, for the tool's test suite
python3 prog.py
ruff check --preview --isolated --select UP005 --fix prog.py
python3 prog.py

Upstream search GitHub issues Tavily Nemotron 3 Super + Ultra

UP005 fix · UP005 assertAlmostEquals method call · unittest assertion method rename behavior · AttributeError to NameError transition in tests

no duplicate or related report 6 hits triaged

Details

program
Float division and rounding in assertion arguments
hazard
UP005 rewrite occurs in assertAlmostEquals with float division arguments; precision-sensitive output shows if fix alters evaluation timing or value.
oracle
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'?
run
2026-10-17T21-11-13-477Z-9jdd-ruff-UP005
generated program (12 lines) and the fix's diff
1import unittest
2class Test(unittest.TestCase):
3 def test(self):
4 val = 1.0 / 3.0
5 try:
6 self.assertAlmostEquals(val, 0.333, places=5)
7 print('assertAlmostEquals passed')
8 except AssertionError as e:
9 print('AssertionError:', type(e).__name__, str(e))
10 self.assertAlmostEqual(val, 0.333, places=5)
11 print('assertEqual passed')
12Test().test()
--- orig.py	2026-10-17 17:11:33.814219965 -0400
+++ fixed.py	2026-10-17 17:11:34.214224066 -0400
@@ -3,7 +3,7 @@
     def test(self):
         val = 1.0 / 3.0
         try:
-            self.assertAlmostEquals(val, 0.333, places=5)
+            self.assertAlmostEqual(val, 0.333, places=5)
             print('assertAlmostEquals passed')
         except AssertionError as e:
             print('AssertionError:', type(e).__name__, str(e))
rule documentation given to the models
# deprecated-unittest-alias (UP005)

Derived from the **pyupgrade** linter.

Fix is always available.

## What it does
Checks for uses of deprecated methods from the `unittest` module.

## Why is this bad?
The `unittest` module has deprecated aliases for some of its methods.
The deprecated aliases were removed in Python 3.12. Instead of aliases,
use their non-deprecated counterparts.

## Example
```python
from unittest import TestCase


class SomeTest(TestCase):
    def test_something(self):
        self.assertEquals(1, 1)
```

Use instead:
```python
from unittest import TestCase


class SomeTest(TestCase):
    def test_something(self):
        self.assertEqual(1, 1)
```

## References
- [Python 3.11 documentation: Deprecated aliases](https://docs.python.org/3.11/library/unittest.html#deprecated-aliases)