[issue33183] Refactoring: replacing some assertTrue by assertIn

Stéphane Blondon report at bugs.python.org
Thu Mar 29 16:07:40 EDT 2018


New submission from Stéphane Blondon <stephane.blondon at gmail.com>:

In several cases, tests use ```self.assertTrue(a in b)```. Using ```self.assertIn(a, b)``` seems to be better.
For examples:
./Lib/test/test_inspect.py:
   self.assertTrue('(po, pk' in repr(sig))
./Lib/test/test_configparser.py:
   self.assertTrue('that_value' in cf['Spacey Bar'])
./Lib/test/test_collections.py:
   self.assertTrue(elem in c)

There are some cases where ```self.assertTrue(a not in b)``` could be replaced by  ```self.assertNotIn(a, b)```

./Lib/tkinter/test/test_ttk/test_widgets.py:
   self.assertTrue('.' not in value)
./Lib/test/mapping_tests.py:
   self.assertTrue(not ('a' in d))
   self.assertTrue('a' not in d)


$ find . -name "*.py" | xargs grep -r "assertTrue.* in "
finds 131 occurences but there are some false positives inside the output.

I can write a patch if you are interested.

----------
components: Tests
messages: 314670
nosy: sblondon
priority: normal
severity: normal
status: open
title: Refactoring: replacing some assertTrue by assertIn
type: enhancement

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33183>
_______________________________________


More information about the Python-bugs-list mailing list