From 5465e48c373b1e65be396696c18c527b342e9de1 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Mon, 11 Feb 2019 11:54:50 +0100 Subject: [PATCH] Fix unittest if run from non-unicode shell When opening files (like os.devnull) in text mode, python uses the shell's default encoding. In case LANG=C or when redirecting (for example), that is just 'ascii', so writing non-ascii strings to /dev/null fails with UnicodeError --- test/test_cnfvar.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/test/test_cnfvar.py b/test/test_cnfvar.py index 2f5355a..046f56a 100755 --- a/test/test_cnfvar.py +++ b/test/test_cnfvar.py @@ -412,7 +412,7 @@ class CnfVarUnittest(unittest.TestCase): def test_read_json_nonascii(self): cnf = cnfvar.read_cnf_json(demo_latin1crap) - with open(os.devnull, "w") as devnull: + with open(os.devnull, "wb") as devnull: cnfvar.print_cnf(cnf, out=devnull) def test_parse_cnf_quotes(self): -- 1.7.1