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.

classification
Title: assertIn should check for membership support before testing
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: brian.curtin, michael.foord
Priority: normal Keywords: needs review, patch

Created on 2010-07-22 17:11 by brian.curtin, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
membership_check.diff brian.curtin, 2010-07-22 17:11 py3k patch
Messages (3)
msg111193 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-07-22 17:11
A recent sysconfig test which should have been skipped on Windows (now fixed) exposed a bug in the assertIn/assertNotIn methods. If the "container" you are testing doesn't support membership testing or iteration, such as None value when a previous call fails, the test is then an error rather than a fail.

Before:
======================================================================
ERROR: test_ldshared_value (test.test_sysconfig.TestSysConfig)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\python-dev\py3k\lib\test\test_sysconfig.py", line 285, in test_ldshar
ed_value
    self.assertIn(ldflags, ldshared)
  File "c:\python-dev\py3k\lib\unittest\case.py", line 797, in assertIn
    if member not in container:
TypeError: argument of type 'NoneType' is not iterable


I believe this should be a fail with AssertionError, rather than an error with TypeError.

======================================================================
FAIL: test_ldshared_value (test.test_sysconfig.TestSysConfig)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\python-dev\py3k\lib\test\test_sysconfig.py", line 285, in test_ldshar
ed_value
    self.assertIn(ldflags, ldshared)
AssertionError: None does not support the `in` operator



The patch adds a check that __contains__, __iter__, or __getitem__ exist on the object and fails the test if none of those are found. It also includes a few test updates.
msg111216 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-07-22 21:12
No, assertIn is for testing for membership in a container. If you pass it something that isn't a container then it indicates an error in the test (or misuse of the assert!).
msg111217 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-07-22 21:14
I knew there was a reason I was thinking my whole idea was slightly ridiculous...duh.
History
Date User Action Args
2022-04-11 14:57:04adminsetgithub: 53576
2010-07-22 21:14:48brian.curtinsetstatus: open -> closed
keywords: patch, patch, needs review
resolution: rejected
messages: + msg111217
2010-07-22 21:12:03michael.foordsetkeywords: patch, patch, needs review

messages: + msg111216
2010-07-22 17:11:18brian.curtincreate