Source: diffoscope Severity: minor Tags: patch diffoscope sets the timezone to UTC to ensure that timezones are consistent from diff output tools. However, it does not call tzset after it does this. Because of this, C code running in the same process may continue to see and use the user's original timezone. In particular, the python-magic module that wraps libmagic is susceptible to this.
I believe this is the source of test_gzip.metadata test failures that have been reported in, e.g., #817193. Test failures look inconsistent because you'll only see it if (a) you're using the python-magic wrapper module, and (b) your current timezone does not align with UTC. A patch is attached. -- System Information: Debian Release: 8.6 APT prefers stable-updates APT policy: (500, 'stable-updates'), (500, 'stable') Architecture: amd64 (x86_64) Kernel: Linux 4.9.0-rc6+ (SMP w/4 CPU cores) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) (ignored: LC_ALL set to en_US.utf8) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system)
>From de145d41ed76e57dcae8dbfc1c7404171ac9c2d8 Mon Sep 17 00:00:00 2001 From: Brett Smith <brettcsm...@brettcsmith.org> Date: Thu, 15 Dec 2016 12:14:42 -0500 Subject: [PATCH] diffoscope: set_locale calls tzset. This is necessary to update timezone information for C code we've pulled in that might've already called it. In particular, the python-magic libmagic wrapper can be affected by this, and print out gzip mtimes in the user's timezone. Accordingly, we call set_locale as a test fixture in test_gzip to make sure things are set up correctly for the metadata difference tests. --- diffoscope/__init__.py | 2 ++ tests/comparators/test_gzip.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/diffoscope/__init__.py b/diffoscope/__init__.py index b1bb1d4..827445f 100644 --- a/diffoscope/__init__.py +++ b/diffoscope/__init__.py @@ -23,6 +23,7 @@ import logging import platform import tempfile import functools +import time from distutils.spawn import find_executable @@ -90,6 +91,7 @@ def set_locale(): os.environ[var] = 'C' os.environ['LC_CTYPE'] = 'C.UTF-8' os.environ['TZ'] = 'UTC' + time.tzset() temp_files = [] diff --git a/tests/comparators/test_gzip.py b/tests/comparators/test_gzip.py index a448820..6481ef6 100644 --- a/tests/comparators/test_gzip.py +++ b/tests/comparators/test_gzip.py @@ -25,7 +25,7 @@ from diffoscope.comparators import specialize from diffoscope.comparators.gzip import GzipFile from diffoscope.comparators.binary import FilesystemFile, NonExistingFile -from utils import data, load_fixture +from utils import data, load_fixture, set_locale TEST_FILE1_PATH = data('test1.gz') TEST_FILE2_PATH = data('test2.gz') -- 2.1.4