This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author barry
Recipients barry, serhiy.storchaka, xdegaye
Date 2017-12-06.15:11:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
In-reply-to <>
On Dec 6, 2017, at 02:06, Xavier de Gaye <> wrote:
> Whatever the change made to fix this issue, it is not possible to add a test case for this change.

Even with say, exception raising mocks for the getters?

> So following the suggestion made by Barry in PR 4696, we can add (in another issue) a new keyword parameter to getnode() named 'methods' whose value may be None (the default, meaning try all the known methods) or a tuple containing a subset of the following methods ('unix', 'ifconfig', 'ip', 'arp', 'lanscan', 'netstat',  'random') that would raise an exception if the value cannot be obtained using one of the requested method tried in the requested order. This would also improve the documentation on the methods getnode() is using. Then if we decide to make the change for 'ip link' in the current issue, one can add a test case that would first test for the avaibility of the ip command and if the command exists would fail if getnode(methods=('ip',)) raises an exception.

I am thinking about this slightly differently.

What if getnode() accepted a `handler` argument and the code was changed to something like this:

1 file changed, 4 insertions(+), 2 deletions(-)
Lib/ | 6 ++++--

modified   Lib/
@@ -656,7 +656,7 @@ def _random_getnode():

 _node = None

-def getnode():
+def getnode(handler=None):
     """Get the hardware address as a 48-bit positive integer.

     The first time this runs, it may launch a separate program, which could
@@ -677,7 +677,9 @@ def getnode():
     for getter in getters + [_random_getnode]:
             _node = getter()
-        except:
+        except Exception as error:
+            if handler is not None:
+                handler(getter, error)
         if _node is not None:
             return _node

`handler` could log some diagnostics, reraise the exception, raise StopIteration, etc.  Then we could use that in the test suite too, because we could mock a getter to raise an exception and then pass in a handler that verified the exception was raised with the expected getter.

(Maybe we spell `handler` as `error_handler`.)
Date User Action Args
2017-12-06 15:11:56barrysetrecipients: + barry, xdegaye, serhiy.storchaka
2017-12-06 15:11:56barrylinkissue32199 messages
2017-12-06 15:11:56barrycreate