Skip to content

Commit d6419aa

Browse files
committed
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().
1 parent f4b2927 commit d6419aa

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

gitlab/tests/test_gitlab.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,15 @@ def resp_get_user_status(url, request):
673673
self.assertEqual(status.emoji, "thumbsup")
674674

675675
def test_todo(self):
676-
todo_content = open(os.path.dirname(__file__) + "/data/todo.json", "r").read()
677-
json_content = json.loads(todo_content)
676+
with open(os.path.dirname(__file__) + "/data/todo.json", "r") as json_file:
677+
todo_content = json_file.read()
678+
json_content = json.loads(todo_content)
679+
encoded_content = todo_content.encode("utf-8")
678680

679681
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/todos", method="get")
680682
def resp_get_todo(url, request):
681683
headers = {"content-type": "application/json"}
682-
content = todo_content.encode("utf-8")
683-
return response(200, content, headers, None, 5, request)
684+
return response(200, encoded_content, headers, None, 5, request)
684685

685686
@urlmatch(
686687
scheme="http",

0 commit comments

Comments
 (0)