So the whole thing with the set_locale test fixture is a little subtle.  The
best reference I found for this is
<http://doc.pytest.org/en/latest/fixture.html#autouse-fixtures-xunit-setup-on-steroids>.

Before I touched this, the autouse=True argument meant it applied to all
other fixtures in the same utils module as it.  In systems where the bug
could occur, the test_gzip metadata test would fail, because the timezone
wasn't necessarily set when python-magic generated a timestamp string for
the gzip1 and gzip2 fixtures.

With my first patch, importing set_locale into the test_gzip module,
combined with autouse=True, meant that it now applied to all the tests and
fixtures in that module too.  This made the tests reliable by making sure
the gzip1 and gzip2 fixtures always rendered a timestamp in UTC.

If you want to make sure it runs before any test, we can do that too.  I've
attached a patch for that as well.
>From b4d0a395066f4b8f86d520e58acdd11dd4eb1a5e Mon Sep 17 00:00:00 2001
From: Brett Smith <brettcsm...@brettcsmith.org>
Date: Thu, 15 Dec 2016 16:14:29 -0500
Subject: [PATCH] tests: Ensure set_locale fixture runs before all tests.

See
<http://doc.pytest.org/en/latest/fixture.html#autouse-fixtures-xunit-setup-on-steroids>
for details about the old and new behavior.
---
 tests/comparators/utils.py | 4 ----
 tests/conftest.py          | 4 ++++
 2 files changed, 4 insertions(+), 4 deletions(-)
 create mode 100644 tests/conftest.py

diff --git a/tests/comparators/utils.py b/tests/comparators/utils.py
index f796378..0b60826 100644
--- a/tests/comparators/utils.py
+++ b/tests/comparators/utils.py
@@ -31,10 +31,6 @@ from diffoscope.presenters.text import output_text
 from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
 
 
-@pytest.fixture(autouse=True)
-def set_locale():
-    diffoscope.set_locale()
-
 def tools_missing(*required):
     return not required or any(find_executable(x) is None for x in required)
 
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..e238f1b
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,4 @@
+import diffoscope
+import pytest
+
+set_locale = pytest.fixture(autouse=True, scope='session')(diffoscope.set_locale)
-- 
2.1.4

Reply via email to