NmapOptionsTest defines test_default_executable twice; the shadowed copy calls a nonexistent assert
NmapOptionsTest defines test_default_executable twice; the first is dead and calls a nonexistent assert
Component: Zenmap (zenmapCore tests)
Affects: all platforms
Tested at: master b97fabd935362f85ad0575632e6d887f4d778b59
Summary
zenmap/zenmapCore/NmapOptions.py defines the same test method twice:
def test_default_executable(self): # line 920
"""Test that there is a default executable member set."""
ops = NmapOptions()
self.assertNotNull(ops.executable)
def test_default_executable(self): # line 925
"""Test that you can set the executable."""
ops = NmapOptions()
ops.executable = "foo"
...The second binding shadows the first, so the class exposes one method, not two. Two consequences:
- The test at line 920 never runs.
NmapOptions.pycontains 21def test_definitions but only 20 distinct names. Suite-wide the discovered tests total 32 authored methods (21 here, 6 inSearchResult.py, 4 inNetworkInventory.py, 1 inStringPool.py), so at most 31 of 32 can ever be collected. - Its body would fail if it ever did run:
self.assertNotNullis not aunittest.TestCasemethod (the correct name isassertIsNotNone).
Reproduction
>>> import inspect, unittest
>>> inspect.getsourcelines(NmapOptionsTest.test_default_executable)[1]
925 # the surviving definition
>>> hasattr(unittest.TestCase, 'assertNotNull')
FalseRe-binding the shadowed body and calling it directly:
AttributeError: 'Resurrected' object has no attribute 'assertNotNull'Fix
Rename the second to match its own docstring and correct the assertion in the first:
def test_default_executable(self):
"""Test that there is a default executable member set."""
ops = NmapOptions()
self.assertIsNotNone(ops.executable)
def test_set_executable(self):
"""Test that you can set the executable."""
...Both then run: 32 tests instead of 31.
Note
This is independent of #3469 (make check-zenmap reports success regardless of
test results), but the two interact: because the runner never fails the build,
this defect could not have been noticed from make check output.
Prior art and scope
No existing issue, PR, commit or list post mentions this. Searched (state=all)
for assertNotNull, test_default_executable, NmapOptions test, shadowed,
zenmap unittest; plus web and nmap-dev searches. The nearest relevant item is
the #85 Zenmap-tests umbrella, which this belongs under.
The defect is present in the oldest commit touching the file, ed2ba4e16808
(2011-11-16), and survived a PEP-8 sweep, a 2015 pep8 fix and the 2022 Python 3 /
PyGObject port.
Scope is small and isolated, not systemic: a full scan of zenmap/ found
assertNotNull exactly once and exactly one duplicate method definition in the
whole tree. NmapOptionsTest is collected by discovery — it is only this one
assertion that silently never runs.
Tested on macOS 26 (arm64) only.
Source: nmap/nmap