Issue 25320: unittest loader.py TypeError when code directory contains a socket (original) (raw)

Created on 2015-10-05 16:43 by Victor van den Elzen, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
patch-with-test.patch Victor van den Elzen,2015-10-20 20:17 review
patch-with-seperate-test.patch Victor van den Elzen,2015-10-20 20:18 review
Messages (10)
msg252342 - (view) Author: Victor van den Elzen (Victor van den Elzen) * Date: 2015-10-05 16:43
Hi, when trying to run tests after upgrading from Python 3.4 to Python 3.5 I encountered the following exception: Traceback (most recent call last): ... File "/usr/lib/python3.5/unittest/loader.py", line 341, in discover tests = list(self._find_tests(start_dir, pattern)) File "/usr/lib/python3.5/unittest/loader.py", line 398, in _find_tests full_path, pattern, namespace) TypeError: 'NoneType' object is not iterable This was caused by a stray socket in my code directory, and the fact that _find_test_path only considers directories and regular files. I attached a suggested fix that just skips all special files. No tests other than "it works on my machine".
msg252825 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2015-10-11 22:04
The fix is appropriate (we might want to think about symlinks in the future). I'd very much like a test for it (in Lib/unittest/test/test_discovery.py) and it should be applied to 3.5, master - older versions had this wrapped up in simpler code and won't fail like this.
msg253249 - (view) Author: Victor van den Elzen (Victor van den Elzen) * Date: 2015-10-20 20:17
patch-with-test.patch is a patch against current tip (c3cec0f77eff+). It applies cleanly to 3.5. It seemed simplest to include the socket in test_find_tests.
msg253250 - (view) Author: Victor van den Elzen (Victor van den Elzen) * Date: 2015-10-20 20:18
Alternatively, patch-with-seperate-test.patch creates a seperate function to test for this issue.
msg255193 - (view) Author: Victor van den Elzen (Victor van den Elzen) * Date: 2015-11-23 16:55
Ping
msg257263 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2016-01-01 02:13
The fix looks ok, however the test seem to contain unnecessary code and it duplicates most of the previous test. I left a more detailed review on rietveld (see the "review" link next to the patch).
msg261790 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-03-15 00:32
New changeset efc9836e0c83 by Robert Collins in branch '3.5': #25320: Handle sockets in directories unittest discovery is scanning. https://hg.python.org/cpython/rev/efc9836e0c83
msg261791 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-03-15 00:33
New changeset 1d72402c1c91 by Robert Collins in branch 'default': #25320: Handle sockets in directories unittest discovery is scanning. https://hg.python.org/cpython/rev/1d72402c1c91
msg261792 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2016-03-15 00:37
Thanks for the patch; the test may be redundant but not enough to matter for now - and the bug really doth need fixing, so I've applied it as-is.
msg263002 - (view) Author: Mike Miller (Mike Miller) Date: 2016-04-07 20:16
Just as a side note, the patch also works for soft links that point to files that don't exist. Thanks for getting this fixed!
History
Date User Action Args
2022-04-11 14:58:22 admin set github: 69507
2016-04-07 20:16:51 Mike Miller set nosy: + Mike Millermessages: +
2016-03-15 00:37:01 rbcollins set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2016-03-15 00:33:40 python-dev set messages: +
2016-03-15 00:32:34 python-dev set nosy: + python-devmessages: +
2016-01-01 02:13:21 ezio.melotti set type: behaviormessages: +
2015-11-23 16:55:23 Victor van den Elzen set messages: +
2015-10-20 20🔞49 Victor van den Elzen set files: - unittest_socket.diff
2015-10-20 20🔞40 Victor van den Elzen set files: + patch-with-seperate-test.patchmessages: +
2015-10-20 20:17:31 Victor van den Elzen set files: + patch-with-test.patchmessages: +
2015-10-11 22:04:54 rbcollins set messages: + stage: patch review
2015-10-09 18:47:36 terry.reedy set nosy: + rbcollins, ezio.melotti, michael.foordversions: + Python 3.6
2015-10-05 16:43:44 Victor van den Elzen create