66from traceback import TIMESTAMP_AFTER_EXC_MSG_RE_GROUP
77
88from test .support import force_not_colorized , script_helper
9- from test .support .os_helper import TESTFN , unlink
9+ from test .support .os_helper import EnvironmentVarGuard , TESTFN , unlink
1010
1111
1212class TracebackTimestampsTests (unittest .TestCase ):
@@ -38,6 +38,11 @@ def cause_exception():
3838 script_file .write (self .flags_script )
3939 self .addCleanup (unlink , self .flags_script_path )
4040
41+ self .env = EnvironmentVarGuard ()
42+ self .env .set ('PYTHONUTF8' , '1' ) # -X utf8=1
43+ self .addCleanup (self .env .__exit__ )
44+
45+
4146 def test_no_traceback_timestamps (self ):
4247 """Test that traceback timestamps are not shown by default"""
4348 result = script_helper .assert_python_ok (self .script_path )
@@ -217,14 +222,14 @@ def test_strip_exc_timestamps_function(self):
217222 with self .subTest (mode ):
218223 result = script_helper .assert_python_failure (
219224 "-X" , f"traceback_timestamps={ mode } " ,
220- "-X" , "utf8=1" , self .script_strip_path
225+ self .script_strip_path
221226 )
222227 output = result .out .decode () + result .err .decode ()
223228
224229 # call strip_exc_timestamps in a process using the same mode as what generated our output.
225230 result = script_helper .assert_python_ok (
226231 "-X" , f"traceback_timestamps={ mode } " ,
227- "-X" , "utf8=1" , self .script_strip_path , output
232+ self .script_strip_path , output
228233 )
229234 stripped_output = result .out .decode () + result .err .decode ()
230235
@@ -239,15 +244,13 @@ def test_strip_exc_timestamps_with_disabled_timestamps(self):
239244 """Test the strip_exc_timestamps function when timestamps are disabled"""
240245 # Run with timestamps disabled
241246 result = script_helper .assert_python_failure (
242- "-X" , "traceback_timestamps=0" ,
243- "-X" , "utf8=1" , self .script_strip_path
247+ "-X" , "traceback_timestamps=0" , self .script_strip_path
244248 )
245249 output = result .out .decode () + result .err .decode ()
246250
247251 # call strip_exc_timestamps in a process using the same mode as what generated our output.
248252 result = script_helper .assert_python_ok (
249- "-X" , "traceback_timestamps=0" ,
250- "-X" , "utf8=1" , self .script_strip_path , output
253+ "-X" , "traceback_timestamps=0" , self .script_strip_path , output
251254 )
252255 stripped_output = result .out .decode () + result .err .decode ()
253256
0 commit comments