diff --git a/gitlab/tests/test_base.py b/gitlab/tests/test_base.py
index 4aa280cda..5a43b1d9d 100644
--- a/gitlab/tests/test_base.py
+++ b/gitlab/tests/test_base.py
@@ -16,11 +16,7 @@
# along with this program. If not, see .
import pickle
-
-try:
- import unittest
-except ImportError:
- import unittest2 as unittest
+import unittest
from gitlab import base
diff --git a/gitlab/tests/test_cli.py b/gitlab/tests/test_cli.py
index 14854996f..04a196115 100644
--- a/gitlab/tests/test_cli.py
+++ b/gitlab/tests/test_cli.py
@@ -16,12 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-from __future__ import print_function
-from __future__ import absolute_import
-
import argparse
import os
import tempfile
+import unittest
try:
from contextlib import redirect_stderr # noqa: H302
@@ -36,11 +34,6 @@ def redirect_stderr(new_target):
sys.stderr = old_target
-try:
- import unittest
-except ImportError:
- import unittest2 as unittest
-
import six
from gitlab import cli
@@ -120,19 +113,19 @@ def test_parse_args(self):
def test_parser(self):
parser = cli._get_parser(gitlab.v4.cli)
- subparsers = None
- for action in parser._actions:
- if type(action) == argparse._SubParsersAction:
- subparsers = action
- break
+ subparsers = next(
+ action
+ for action in parser._actions
+ if isinstance(action, argparse._SubParsersAction)
+ )
self.assertIsNotNone(subparsers)
self.assertIn("project", subparsers.choices)
- user_subparsers = None
- for action in subparsers.choices["project"]._actions:
- if type(action) == argparse._SubParsersAction:
- user_subparsers = action
- break
+ user_subparsers = next(
+ action
+ for action in subparsers.choices["project"]._actions
+ if isinstance(action, argparse._SubParsersAction)
+ )
self.assertIsNotNone(user_subparsers)
self.assertIn("list", user_subparsers.choices)
self.assertIn("get", user_subparsers.choices)
@@ -145,10 +138,10 @@ def test_parser(self):
actions = user_subparsers.choices["create"]._option_string_actions
self.assertFalse(actions["--description"].required)
- user_subparsers = None
- for action in subparsers.choices["group"]._actions:
- if type(action) == argparse._SubParsersAction:
- user_subparsers = action
- break
+ user_subparsers = next(
+ action
+ for action in subparsers.choices["group"]._actions
+ if isinstance(action, argparse._SubParsersAction)
+ )
actions = user_subparsers.choices["create"]._option_string_actions
self.assertTrue(actions["--name"].required)
diff --git a/gitlab/tests/test_config.py b/gitlab/tests/test_config.py
index 9e19ce82b..a43f97758 100644
--- a/gitlab/tests/test_config.py
+++ b/gitlab/tests/test_config.py
@@ -15,10 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-try:
- import unittest
-except ImportError:
- import unittest2 as unittest
+import unittest
import mock
import six
diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py
index 5688cd2de..665810c9e 100644
--- a/gitlab/tests/test_gitlab.py
+++ b/gitlab/tests/test_gitlab.py
@@ -16,17 +16,11 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-from __future__ import print_function
-
import os
import pickle
import tempfile
import json
-
-try:
- import unittest
-except ImportError:
- import unittest2 as unittest
+import unittest
from httmock import HTTMock # noqa
from httmock import response # noqa
@@ -479,7 +473,7 @@ def resp_cont(url, request):
self.gl.auth()
self.assertEqual(self.gl.user.username, name)
self.assertEqual(self.gl.user.id, id_)
- self.assertEqual(type(self.gl.user), CurrentUser)
+ self.assertIsInstance(self.gl.user, CurrentUser)
def test_hooks(self):
@urlmatch(
@@ -492,7 +486,7 @@ def resp_get_hook(url, request):
with HTTMock(resp_get_hook):
data = self.gl.hooks.get(1)
- self.assertEqual(type(data), Hook)
+ self.assertIsInstance(data, Hook)
self.assertEqual(data.url, "testurl")
self.assertEqual(data.id, 1)
@@ -507,7 +501,7 @@ def resp_get_project(url, request):
with HTTMock(resp_get_project):
data = self.gl.projects.get(1)
- self.assertEqual(type(data), Project)
+ self.assertIsInstance(data, Project)
self.assertEqual(data.name, "name")
self.assertEqual(data.id, 1)
@@ -553,7 +547,7 @@ def resp_get_group(url, request):
with HTTMock(resp_get_group):
data = self.gl.groups.get(1)
- self.assertEqual(type(data), Group)
+ self.assertIsInstance(data, Group)
self.assertEqual(data.name, "name")
self.assertEqual(data.path, "path")
self.assertEqual(data.id, 1)
@@ -586,7 +580,7 @@ def resp_get_user(self, url, request):
def test_users(self):
with HTTMock(self.resp_get_user):
user = self.gl.users.get(1)
- self.assertEqual(type(user), User)
+ self.assertIsInstance(user, User)
self.assertEqual(user.name, "name")
self.assertEqual(user.id, 1)
@@ -607,7 +601,7 @@ def resp_get_user_status(url, request):
user = self.gl.users.get(1)
with HTTMock(resp_get_user_status):
status = user.status.get()
- self.assertEqual(type(status), UserStatus)
+ self.assertIsInstance(status, UserStatus)
self.assertEqual(status.message, "test")
self.assertEqual(status.emoji, "thumbsup")
@@ -636,7 +630,7 @@ def resp_mark_as_done(url, request):
with HTTMock(resp_get_todo):
todo = self.gl.todos.list()[0]
- self.assertEqual(type(todo), Todo)
+ self.assertIsInstance(todo, Todo)
self.assertEqual(todo.id, 102)
self.assertEqual(todo.target_type, "MergeRequest")
self.assertEqual(todo.target["assignee"]["username"], "root")
@@ -683,10 +677,10 @@ def resp_update_submodule(url, request):
"committer_name": "Author",
"committer_email": "author@example.com",
"created_at": "2018-09-20T09:26:24.000-07:00",
- "message": "Message",
- "parent_ids": [ "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" ],
+ "message": "Message",
+ "parent_ids": [ "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" ],
"committed_date": "2018-09-20T09:26:24.000-07:00",
- "authored_date": "2018-09-20T09:26:24.000-07:00",
+ "authored_date": "2018-09-20T09:26:24.000-07:00",
"status": null}"""
content = content.encode("utf-8")
return response(200, content, headers, None, 5, request)
@@ -724,5 +718,5 @@ class MyGitlab(gitlab.Gitlab):
config_path = self._default_config()
gl = MyGitlab.from_config("one", [config_path])
- self.assertEqual(type(gl).__name__, "MyGitlab")
+ self.assertIsInstance(gl, MyGitlab)
os.unlink(config_path)
diff --git a/gitlab/tests/test_mixins.py b/gitlab/tests/test_mixins.py
index 56be8f370..749c0d260 100644
--- a/gitlab/tests/test_mixins.py
+++ b/gitlab/tests/test_mixins.py
@@ -16,12 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-from __future__ import print_function
-
-try:
- import unittest
-except ImportError:
- import unittest2 as unittest
+import unittest
from httmock import HTTMock # noqa
from httmock import response # noqa
diff --git a/gitlab/tests/test_types.py b/gitlab/tests/test_types.py
index 4ce065e4a..5b9f2caf8 100644
--- a/gitlab/tests/test_types.py
+++ b/gitlab/tests/test_types.py
@@ -15,10 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-try:
- import unittest
-except ImportError:
- import unittest2 as unittest
+import unittest
from gitlab import types
diff --git a/gitlab/tests/test_utils.py b/gitlab/tests/test_utils.py
index f84f9544b..b57dedadb 100644
--- a/gitlab/tests/test_utils.py
+++ b/gitlab/tests/test_utils.py
@@ -15,10 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-try:
- import unittest
-except ImportError:
- import unittest2 as unittest
+import unittest
from gitlab import utils