diff --git a/html5lib/tests/test_encoding.py b/html5lib/tests/test_encoding.py
index <HASH>..<HASH> 100644
--- a/html5lib/tests/test_encoding.py
+++ b/html5lib/tests/test_encoding.py
@@ -54,8 +54,8 @@ def test_encoding():
 try:
     import chardet
     def test_chardet():
-        data = open(os.path.join(test_dir, "encoding" , "chardet", "test_big5.txt"), "rb").read()
-        encoding = inputstream.HTMLInputStream(data).charEncoding
-        assert encoding[0].lower() == "big5"
+        with open(os.path.join(test_dir, "encoding" , "chardet", "test_big5.txt"), "rb") as fp:
+            encoding = inputstream.HTMLInputStream(fp.read()).charEncoding
+            assert encoding[0].lower() == "big5"
 except ImportError:
     print("chardet not found, skipping chardet tests")
Fix #<I>: ResourceWarning on test_encoding (test_big5.txt unclosed)