diff options
author | Derek Schrock <dereks@lifeofadishwasher.com> | 2019-10-12 18:26:30 -0400 |
---|---|---|
committer | Derek Schrock <dereks@lifeofadishwasher.com> | 2019-10-12 19:19:55 -0400 |
commit | d6419aa86d6ad385e15d685bf47242bb6c67653e (patch) | |
tree | 8cd1198d01937b1e4323ea1d150d56c32a4381c9 | |
parent | f4b29278771e48320e2da4bacc4544d263d1754c (diff) | |
download | gitlab-d6419aa86d6ad385e15d685bf47242bb6c67653e.tar.gz |
test: remove warning about open files from test_todo()
When running unittests python warns that the json file from test_todo()
was still open. Use with to open, read, and create encoded json data
that is used by resp_get_todo().
-rw-r--r-- | gitlab/tests/test_gitlab.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py index bd968b1..835e035 100644 --- a/gitlab/tests/test_gitlab.py +++ b/gitlab/tests/test_gitlab.py @@ -673,14 +673,15 @@ class TestGitlab(unittest.TestCase): self.assertEqual(status.emoji, "thumbsup") def test_todo(self): - todo_content = open(os.path.dirname(__file__) + "/data/todo.json", "r").read() - json_content = json.loads(todo_content) + with open(os.path.dirname(__file__) + "/data/todo.json", "r") as json_file: + todo_content = json_file.read() + json_content = json.loads(todo_content) + encoded_content = todo_content.encode("utf-8") @urlmatch(scheme="http", netloc="localhost", path="/api/v4/todos", method="get") def resp_get_todo(url, request): headers = {"content-type": "application/json"} - content = todo_content.encode("utf-8") - return response(200, content, headers, None, 5, request) + return response(200, encoded_content, headers, None, 5, request) @urlmatch( scheme="http", |