summaryrefslogtreecommitdiff
path: root/tests/test_cli.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2017-10-28 17:07:09 -0700
committerJon Dufresne <jon.dufresne@gmail.com>2017-10-28 17:07:09 -0700
commitacaf00cbaf32e7a14e39bcc0a5fd774a5385faa0 (patch)
tree48a8f6022b722d9f23ed0c483d5f0ebf14c0d085 /tests/test_cli.py
parentf8825153da66289c021252f0b221c16302224a86 (diff)
downloadsqlparse-acaf00cbaf32e7a14e39bcc0a5fd774a5385faa0.tar.gz
Fix unclosed file warnings discovered during tests
Appear as: ResourceWarning: unclosed file ... Always explicitly close files or detach file wrappers.
Diffstat (limited to 'tests/test_cli.py')
-rw-r--r--tests/test_cli.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 18c6fcb..485afd3 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -115,9 +115,10 @@ def test_encoding_stdin_utf8(filepath, load_file, capfd):
path = filepath('encoding_utf8.sql')
expected = load_file('encoding_utf8.sql', 'utf-8')
old_stdin = sys.stdin
- sys.stdin = open(path, 'r')
- sys.stdout.encoding = 'utf-8'
- sqlparse.cli.main(['-'])
+ with open(path, 'r') as f:
+ sys.stdin = f
+ sys.stdout.encoding = 'utf-8'
+ sqlparse.cli.main(['-'])
sys.stdin = old_stdin
out, _ = capfd.readouterr()
assert out == expected