Repository: coala/coala

Issue:
pytest-3.1 raises lots of warnings running our tests
Latest `pytest-3.1.x` versions raise several warnings when running our tests, mostly telling that `unittest` functions `assertEquals` and `assertRaisesRegexp` should not be used anymore. We should get rid of those warnings...


Discussion:
This is the list of warnings that are output by pytest 3.1

```
coalib/misc/Shell.py::coalib.misc.Shell.run_interactive_shell_command
  /usr/lib64/python3.6/doctest.py:1841: ResourceWarning: unclosed file <_io.BufferedRandom name=8>
    test.globs.clear()

tests/coalaCITest.py::coalaCITest::test_find_issues
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression [^\/]*\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/coalaDeleteOrigTest.py::coalaDeleteOrigTest::test_normal_running
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression [^\/]*\.orig\Z(?ms)
    match = re.compile(translate(pattern)).match

tests/coalaJSONTest.py::coalaJSONTest::test_show_all_bears
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression .*[^\/]*\.py\Z(?ms)
    match = re.compile(translate(pattern)).match

tests/bearlib/languages/LanguageTest.py::LanguageAttributeErrorTest::test_attribute_list_empy
  /home/thomas/gitrepos/coala/tests/bearlib/languages/LanguageTest.py:28: DeprecationWarning: Please use assertRaisesRegex instead.
    with self.assertRaisesRegexp(AttributeError, 'no available attribute'):

tests/bearlib/languages/LanguageTest.py::LanguageAttributeErrorTest::test_invalid_attribute
  /home/thomas/gitrepos/coala/tests/bearlib/languages/LanguageTest.py:24: DeprecationWarning: Please use assertRaisesRegex instead.
    with self.assertRaisesRegexp(AttributeError, 'not a valid attribute'):

tests/bears/BearTest.py::BearDownloadTest::test_connection_timeout_mocked
  /home/thomas/gitrepos/coala/tests/bears/BearTest.py:364: DeprecationWarning: Please use assertRaisesRegex instead.
    with self.assertRaisesRegexp(exc, '^$'):

tests/bears/BearTest.py::BearDownloadTest::test_read_broken
  /home/thomas/gitrepos/coala/tests/bears/BearTest.py:377: DeprecationWarning: Please use assertRaisesRegex instead.
    with self.assertRaisesRegexp(exc, 'Fake read timeout'):
  /home/thomas/gitrepos/coala/tests/bears/BearTest.py:382: ResourceWarning: unclosed file <_io.BufferedReader name='/home/thomas/.local/share/coala-bears/TestBear/test.html'>
    self.assertEqual(open(self.file_location, 'rb').read(),

tests/bears/BearTest.py::BearDownloadTest::test_status_code_error
  /home/thomas/gitrepos/coala/tests/bears/BearTest.py:387: DeprecationWarning: Please use assertRaisesRegex instead.
    with self.assertRaisesRegexp(exc, '418 Client Error'):

tests/collecting/CollectorsTest.py::CollectFilesTest::test_file_collection
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression [^\/]*2\.py\Z(?ms)
    match = re.compile(translate(pattern)).match

tests/collecting/CollectorsTest.py::CollectFilesTest::test_ignored
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression \/home\/thomas\/gitr (truncated)
    for pat in _iter_alternatives(pattern))

tests/collecting/CollectorsTest.py::CollectFilesTest::test_limited
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression [^\/]*py\Z(?ms)
    match = re.compile(translate(pattern)).match
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression \/home\/thomas\/gitr (truncated)
    for pat in _iter_alternatives(pattern))

tests/collecting/CollectorsTest.py::CollectDirsTest::test_ignored
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression \/home\/thomas\/gitr (truncated)
    for pat in _iter_alternatives(pattern))

tests/collecting/CollectorsTest.py::CollectBearsTest::test_no_duplications
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression [^\/]*\.py\Z(?ms)
    match = re.compile(translate(pattern)).match

tests/core/BearTest.py::BearTest::test_download_cached_file_connection_timeout_mocked
  /home/thomas/gitrepos/coala/tests/core/BearTest.py:210: DeprecationWarning: Please use assertRaisesRegex instead.
    with self.assertRaisesRegexp(exc, '^$'):

tests/core/BearTest.py::BearTest::test_download_cached_file_status_code_error
  /home/thomas/gitrepos/coala/tests/core/BearTest.py:216: DeprecationWarning: Please use assertRaisesRegex instead.
    with self.assertRaisesRegexp(exc, '418 Client Error'):

tests/output/JSONEncoderTest.py::JSONEncoderTest::test_builtins
  /home/thomas/gitrepos/coala/tests/output/JSONEncoderTest.py:59: DeprecationWarning: Please use assertEqual instead.
    self.assertEquals('"test"', json.dumps('test', **self.kw))

tests/output/JSONEncoderTest.py::JSONEncoderTest::test_class1
  /home/thomas/gitrepos/coala/tests/output/JSONEncoderTest.py:86: DeprecationWarning: Please use assertEqual instead.
    self.assertEquals('{"a": 0}', json.dumps(tc1, **self.kw))

tests/output/JSONEncoderTest.py::JSONEncoderTest::test_class2
  /home/thomas/gitrepos/coala/tests/output/JSONEncoderTest.py:93: DeprecationWarning: Please use assertEqual instead.
    json.dumps(tc2, **self.kw))

tests/output/JSONEncoderTest.py::JSONEncoderTest::test_class3
  /home/thomas/gitrepos/coala/tests/output/JSONEncoderTest.py:98: DeprecationWarning: Please use assertEqual instead.
    json.dumps(tc3, **self.kw))

tests/output/JSONEncoderTest.py::JSONEncoderTest::test_dict
  /home/thomas/gitrepos/coala/tests/output/JSONEncoderTest.py:70: DeprecationWarning: Please use assertEqual instead.
    self.assertEquals('{"0": 1}', json.dumps({0: 1}, **self.kw))

tests/output/JSONEncoderTest.py::JSONEncoderTest::test_iter
  /home/thomas/gitrepos/coala/tests/output/JSONEncoderTest.py:65: DeprecationWarning: Please use assertEqual instead.
    self.assertEquals('[0, 1]', json.dumps([0, 1], **self.kw))

tests/output/JSONEncoderTest.py::JSONEncoderTest::test_time
  /home/thomas/gitrepos/coala/tests/output/JSONEncoderTest.py:77: DeprecationWarning: Please use assertEqual instead.
    json.dumps(tf, **self.kw))

tests/parsing/DefaultArgParserTest.py::CustomFormatterTest::test_metavar_in_usage
  /home/thomas/gitrepos/coala/tests/parsing/DefaultArgParserTest.py:26: DeprecationWarning: Please use assertEqual instead.
    self.assertEquals(match.group(1), '-a [BOOL]')

tests/parsing/DefaultArgParserTest.py::CustomFormatterTest::test_metavar_not_in_optional_args_sections
  /home/thomas/gitrepos/coala/tests/parsing/DefaultArgParserTest.py:33: DeprecationWarning: Please use assertEqual instead.
    self.assertEquals(match.group(1), '-a, --all')

tests/parsing/GlobbingTest.py::FnmatchTest::test_alternatives
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression a\Z(?ms)
    for pat in _iter_alternatives(pattern))
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression b\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/parsing/GlobbingTest.py::FnmatchTest::test_asterisk
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression a[^\/]*b\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/parsing/GlobbingTest.py::FnmatchTest::test_circumflex_in_set
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression [\^abc]\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/parsing/GlobbingTest.py::FnmatchTest::test_double_asterisk
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression a.*[^\/]*b\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/parsing/GlobbingTest.py::FnmatchTest::test_empty_set
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression a\[\]b\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/parsing/GlobbingTest.py::FnmatchTest::test_escaped_bracket
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression []ab]\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/parsing/GlobbingTest.py::FnmatchTest::test_home_dir
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression \/home\/thomas\/a\/b (truncated)
    for pat in _iter_alternatives(pattern))

tests/parsing/GlobbingTest.py::FnmatchTest::test_multiple_patterns
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression a.*[^\/]*c\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/parsing/GlobbingTest.py::FnmatchTest::test_negative_set
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression [^ab]\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/parsing/GlobbingTest.py::FnmatchTest::test_questionmark
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression a.b\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/parsing/GlobbingTest.py::FnmatchTest::test_set_precedence
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression \(a\|[b)]\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/parsing/GlobbingTest.py::FnmatchTest::test_single_sequence
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression [ab]\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/parsing/GlobbingTest.py::GlobTest::test_collect_all
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression [^\/]*\Z(?ms)
    match = re.compile(translate(pattern)).match

tests/parsing/GlobbingTest.py::GlobTest::test_collect_brackets
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression SubDir[12]\Z(?ms)
    match = re.compile(translate(pattern)).match
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression File[[]with[]]bracke (truncated)
    match = re.compile(translate(pattern)).match

tests/parsing/GlobbingTest.py::GlobTest::test_collect_dirs
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression Sub[^\/]*\Z(?ms)
    match = re.compile(translate(pattern)).match

tests/parsing/GlobbingTest.py::GlobTest::test_collect_files
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression File1.\.py\Z(?ms)
    match = re.compile(translate(pattern)).match

tests/parsing/GlobbingTest.py::GlobTest::test_collect_or
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression File.\.x\Z(?ms)
    match = re.compile(translate(pattern)).match
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression File.\.y\Z(?ms)
    match = re.compile(translate(pattern)).match
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression File.\.z\Z(?ms)
    match = re.compile(translate(pattern)).match

tests/parsing/GlobbingTest.py::GlobTest::test_collect_parentheses
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression File[(]with\)parenth (truncated)
    match = re.compile(translate(pattern)).match

tests/parsing/GlobbingTest.py::GlobTest::test_collect_recursive_part_of_basename
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression .*[^\/]*\.py\Z(?ms)
    match = re.compile(translate(pattern)).match
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression .*[^\/]*\.[xy]\Z(?ms (truncated)
    match = re.compile(translate(pattern)).match

tests/parsing/GlobbingTest.py::GlobTest::test_no_dirname
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression [^\/]*Dir.\Z(?ms)
    match = re.compile(translate(pattern)).match

tests/parsing/GlobbingTest.py::GlobTest::test_wildcard_dir
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:295: DeprecationWarning: Flags not at the start of the expression SubDir.\Z(?ms)
    match = re.compile(translate(pattern)).match

tests/processes/ProcessingTest.py::ProcessingTest::test_ignore_glob
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression line[^\/]*\Z(?ms)
    for pat in _iter_alternatives(pattern))
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression space[^\/]*\Z(?ms)
    for pat in _iter_alternatives(pattern))
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression py[^\/]*\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/processes/ProcessingTest.py::ProcessingTest::test_ignore_results
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression something\Z(?ms)
    for pat in _iter_alternatives(pattern))
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression else\Z(?ms)
    for pat in _iter_alternatives(pattern))
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression not\ origin\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/processes/ProcessingTest.py::ProcessingTest_AutoapplyActions::test_applicable_action
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression Z[^\/]*\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/processes/ProcessingTest.py::ProcessingTest_AutoapplyActions::test_failing_action
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression YBear\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/processes/ProcessingTest.py::ProcessingTest_AutoapplyActions::test_without_default_action_and_unapplicable
  /home/thomas/gitrepos/coala/coalib/parsing/Globbing.py:233: DeprecationWarning: Flags not at the start of the expression NoBear\Z(?ms)
    for pat in _iter_alternatives(pattern))

tests/results/result_actions/ApplyPatchActionTest.py::ApplyPatchActionTest::test_apply_rename
  /home/thomas/gitrepos/coala/tests/results/result_actions/ApplyPatchActionTest.py:118: ResourceWarning: unclosed file <_io.TextIOWrapper name='/tmp/tmpbu9i6owm.renamed' mode='r' encoding='UTF-8'>
    file_dict = {f_a+'.renamed': open(f_a+'.renamed').readlines()}
```

Resolving patch:
diff --git a/coalib/parsing/Globbing.py b/coalib/parsing/Globbing.py
--- a/coalib/parsing/Globbing.py
+++ b/coalib/parsing/Globbing.py
@@ -191,7 +191,7 @@ def translate(pattern):
                 regex += '[' + sequence + ']'
         else:
             regex = regex + re.escape(char)
-    return regex + '\\Z(?ms)'
+    return '(?ms)' + regex + '\\Z'
 
 
 def fnmatch(name, globs):


Test patch:
diff --git a/tests/bearlib/languages/LanguageTest.py b/tests/bearlib/languages/LanguageTest.py
--- a/tests/bearlib/languages/LanguageTest.py
+++ b/tests/bearlib/languages/LanguageTest.py
@@ -21,9 +21,9 @@ def tearDown(self):
         pass
 
     def test_invalid_attribute(self):
-        with self.assertRaisesRegexp(AttributeError, 'not a valid attribute'):
+        with self.assertRaisesRegex(AttributeError, 'not a valid attribute'):
             self.lang_cpp.not_an_attribute
 
     def test_attribute_list_empy(self):
-        with self.assertRaisesRegexp(AttributeError, 'no available attribute'):
+        with self.assertRaisesRegex(AttributeError, 'no available attribute'):
             self.lang_unknown.not_an_attribute
diff --git a/tests/bears/BearTest.py b/tests/bears/BearTest.py
--- a/tests/bears/BearTest.py
+++ b/tests/bears/BearTest.py
@@ -364,7 +364,7 @@ def test_connection_timeout_mocked(self):
         exc = requests.exceptions.ConnectTimeout
         with requests_mock.Mocker() as reqmock:
             reqmock.get(self.mock_url, exc=exc)
-            with self.assertRaisesRegexp(exc, '^$'):
+            with self.assertRaisesRegex(exc, '^$'):
                 self.uut.download_cached_file(
                     self.mock_url, self.filename)
 
@@ -380,17 +380,18 @@ def test_read_broken(self):
 
         with requests_mock.Mocker() as reqmock:
             reqmock.get(self.mock_url, body=fake_content_provider)
-            with self.assertRaisesRegexp(exc, 'Fake read timeout'):
+            with self.assertRaisesRegex(exc, 'Fake read timeout'):
                 self.uut.download_cached_file(
                     self.mock_url, self.filename)
 
         self.assertTrue(isfile(self.file_location))
-        self.assertEqual(open(self.file_location, 'rb').read(),
-                         b''.join(fake_content))
+
+        with open(self.file_location, 'rb') as fh:
+            self.assertEqual(fh.read(), b''.join(fake_content))
 
     def test_status_code_error(self):
         exc = requests.exceptions.HTTPError
-        with self.assertRaisesRegexp(exc, '418 Client Error'):
+        with self.assertRaisesRegex(exc, '418 Client Error'):
             self.uut.download_cached_file(
                 'http://httpbin.org/status/418', self.filename)
 
diff --git a/tests/core/BearTest.py b/tests/core/BearTest.py
--- a/tests/core/BearTest.py
+++ b/tests/core/BearTest.py
@@ -211,13 +211,13 @@ def test_download_cached_file_connection_timeout_mocked(self):
         exc = requests.exceptions.ConnectTimeout
         with requests_mock.Mocker() as reqmock:
             reqmock.get(mock_url, exc=exc)
-            with self.assertRaisesRegexp(exc, '^$'):
+            with self.assertRaisesRegex(exc, '^$'):
                 Bear.download_cached_file(
                     mock_url, 'test.html')
 
     def test_download_cached_file_status_code_error(self):
         exc = requests.exceptions.HTTPError
-        with self.assertRaisesRegexp(exc, '418 Client Error'):
+        with self.assertRaisesRegex(exc, '418 Client Error'):
             Bear.download_cached_file(
                 'http://httpbin.org/status/418', 'test.html')
 
diff --git a/tests/output/JSONEncoderTest.py b/tests/output/JSONEncoderTest.py
--- a/tests/output/JSONEncoderTest.py
+++ b/tests/output/JSONEncoderTest.py
@@ -56,25 +56,25 @@ class JSONEncoderTest(unittest.TestCase):
     kw = {'cls': JSONEncoder, 'sort_keys': True}
 
     def test_builtins(self):
-        self.assertEquals('"test"', json.dumps('test', **self.kw))
-        self.assertEquals('1', json.dumps(1, **self.kw))
-        self.assertEquals('true', json.dumps(True, **self.kw))
-        self.assertEquals('null', json.dumps(None, **self.kw))
+        self.assertEqual('"test"', json.dumps('test', **self.kw))
+        self.assertEqual('1', json.dumps(1, **self.kw))
+        self.assertEqual('true', json.dumps(True, **self.kw))
+        self.assertEqual('null', json.dumps(None, **self.kw))
 
     def test_iter(self):
-        self.assertEquals('[0, 1]', json.dumps([0, 1], **self.kw))
-        self.assertEquals('[0, 1]', json.dumps((0, 1), **self.kw))
-        self.assertEquals('[0, 1]', json.dumps(range(2), **self.kw))
+        self.assertEqual('[0, 1]', json.dumps([0, 1], **self.kw))
+        self.assertEqual('[0, 1]', json.dumps((0, 1), **self.kw))
+        self.assertEqual('[0, 1]', json.dumps(range(2), **self.kw))
 
     def test_dict(self):
-        self.assertEquals('{"0": 1}', json.dumps({0: 1}, **self.kw))
-        self.assertEquals('{"0": 1}', json.dumps({'0': 1}, **self.kw))
-        self.assertEquals('{"0": "1"}', json.dumps({'0': '1'}, **self.kw))
+        self.assertEqual('{"0": 1}', json.dumps({0: 1}, **self.kw))
+        self.assertEqual('{"0": 1}', json.dumps({'0': 1}, **self.kw))
+        self.assertEqual('{"0": "1"}', json.dumps({'0': '1'}, **self.kw))
 
     def test_time(self):
         tf = datetime.today()
-        self.assertEquals('"' + tf.isoformat() + '"',
-                          json.dumps(tf, **self.kw))
+        self.assertEqual('"' + tf.isoformat() + '"',
+                         json.dumps(tf, **self.kw))
 
     def test_re_object(self):
         uut = re.compile('x')
@@ -83,19 +83,19 @@ def test_re_object(self):
 
     def test_class1(self):
         tc1 = TestClass1()
-        self.assertEquals('{"a": 0}', json.dumps(tc1, **self.kw))
-        self.assertEquals('[{"a": 0}]', json.dumps([tc1], **self.kw))
-        self.assertEquals('{"0": {"a": 0}}', json.dumps({0: tc1}, **self.kw))
+        self.assertEqual('{"a": 0}', json.dumps(tc1, **self.kw))
+        self.assertEqual('[{"a": 0}]', json.dumps([tc1], **self.kw))
+        self.assertEqual('{"0": {"a": 0}}', json.dumps({0: tc1}, **self.kw))
 
     def test_class2(self):
         tc2 = TestClass2()
-        self.assertEquals('{"a": 0, "b": {"a": 0}}',
-                          json.dumps(tc2, **self.kw))
+        self.assertEqual('{"a": 0, "b": {"a": 0}}',
+                         json.dumps(tc2, **self.kw))
 
     def test_class3(self):
         tc3 = TestClass3()
-        self.assertEquals('{"key": "val"}',
-                          json.dumps(tc3, **self.kw))
+        self.assertEqual('{"key": "val"}',
+                         json.dumps(tc3, **self.kw))
 
     def test_propertied_class(self):
         uut = PropertiedClass()
diff --git a/tests/parsing/DefaultArgParserTest.py b/tests/parsing/DefaultArgParserTest.py
--- a/tests/parsing/DefaultArgParserTest.py
+++ b/tests/parsing/DefaultArgParserTest.py
@@ -23,11 +23,11 @@ def test_metavar_in_usage(self):
                           self.output,
                           flags=re.DOTALL)
         self.assertIsNotNone(match)
-        self.assertEquals(match.group(1), '-a [BOOL]')
+        self.assertEqual(match.group(1), '-a [BOOL]')
 
     def test_metavar_not_in_optional_args_sections(self):
         match = re.search('optional arguments:.+(-a, --all).*',
                           self.output,
                           flags=re.DOTALL)
         self.assertIsNotNone(match)
-        self.assertEquals(match.group(1), '-a, --all')
+        self.assertEqual(match.group(1), '-a, --all')
diff --git a/tests/results/result_actions/ApplyPatchActionTest.py b/tests/results/result_actions/ApplyPatchActionTest.py
--- a/tests/results/result_actions/ApplyPatchActionTest.py
+++ b/tests/results/result_actions/ApplyPatchActionTest.py
@@ -115,7 +115,8 @@ def test_apply_rename(self):
                       file_diff_dict)
             self.assertFalse(isfile(f_a+'.renamed.orig'))
 
-            file_dict = {f_a+'.renamed': open(f_a+'.renamed').readlines()}
+            with open(f_a+'.renamed') as fh:
+                file_dict = {f_a+'.renamed': fh.readlines()}
 
             self.assertEqual(file_dict, expected_file_dict)
             # Recreate file so that context manager make_temp() can delete it