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.

Title: unittest TypeError when code directory contains a socket
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 3.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Mike Miller, Victor van den Elzen, ezio.melotti, michael.foord, python-dev, rbcollins
Priority: normal Keywords: patch

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.

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/", line 341, in discover
    tests = list(self._find_tests(start_dir, pattern))
  File "/usr/lib/python3.5/unittest/", 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/ 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
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.
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.
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!
Date User Action Args
2022-04-11 14:58:22adminsetgithub: 69507
2016-04-07 20:16:51Mike Millersetnosy: + Mike Miller
messages: + msg263002
2016-03-15 00:37:01rbcollinssetstatus: open -> closed
resolution: fixed
messages: + msg261792

stage: patch review -> resolved
2016-03-15 00:33:40python-devsetmessages: + msg261791
2016-03-15 00:32:34python-devsetnosy: + python-dev
messages: + msg261790
2016-01-01 02:13:21ezio.melottisettype: behavior
messages: + msg257263
2015-11-23 16:55:23Victor van den Elzensetmessages: + msg255193
2015-10-20 20:18:49Victor van den Elzensetfiles: - unittest_socket.diff
2015-10-20 20:18:40Victor van den Elzensetfiles: + patch-with-seperate-test.patch

messages: + msg253250
2015-10-20 20:17:31Victor van den Elzensetfiles: + patch-with-test.patch

messages: + msg253249
2015-10-11 22:04:54rbcollinssetmessages: + msg252825
stage: patch review
2015-10-09 18:47:36terry.reedysetnosy: + rbcollins, ezio.melotti, michael.foord

versions: + Python 3.6
2015-10-05 16:43:44Victor van den Elzencreate