diff options
author | Alexander Shadchin <alexandr.shadchin@gmail.com> | 2019-02-27 17:49:16 +0300 |
---|---|---|
committer | Paul Ganssle <paul@ganssle.io> | 2019-11-02 11:46:54 -0400 |
commit | 154d391d5d6f8d3c2e5b086f833620a8e78e0097 (patch) | |
tree | 7346f8a192f4ac9fd6ca4e40fc33a492dfb5b0a9 | |
parent | c31392f853819b8e5db0d032f6d79aadb4100a2b (diff) | |
download | dateutil-git-154d391d5d6f8d3c2e5b086f833620a8e78e0097.tar.gz |
Auto-skip tests when TZ can't be changed.
At the moment these tests are skipped ad-hoc in the test suite, but we
can use `pytest.skip` in the context manager itself to skip them
automatically and make things easier on ourselves.
-rw-r--r-- | changelog.d/893.misc.rst | 2 | ||||
-rw-r--r-- | dateutil/test/_common.py | 8 | ||||
-rw-r--r-- | dateutil/test/test_tz.py | 8 |
3 files changed, 9 insertions, 9 deletions
diff --git a/changelog.d/893.misc.rst b/changelog.d/893.misc.rst new file mode 100644 index 0000000..fed687e --- /dev/null +++ b/changelog.d/893.misc.rst @@ -0,0 +1,2 @@ +Fix tests if TZ not change allowed. +Patch by @shadchin (gh pr #893) diff --git a/dateutil/test/_common.py b/dateutil/test/_common.py index e46dc4b..b8d2047 100644 --- a/dateutil/test/_common.py +++ b/dateutil/test/_common.py @@ -6,6 +6,8 @@ import warnings import tempfile import pickle +import pytest + class PicklableMixin(object): def _get_nobj_bytes(self, obj, dump_kwargs, load_kwargs): @@ -85,7 +87,11 @@ class TZContextBase(object): def __enter__(self): if not self.tz_change_allowed(): - raise ValueError(self.tz_change_disallowed_message()) + msg = self.tz_change_disallowed_message() + pytest.skip(msg) + + # If this is used outside of a test suite, we still want an error. + raise ValueError(msg) # pragma: no cover self._old_tz = self.get_current_tz() self.set_current_tz(self.tzval) diff --git a/dateutil/test/test_tz.py b/dateutil/test/test_tz.py index 4180199..d628826 100644 --- a/dateutil/test/test_tz.py +++ b/dateutil/test/test_tz.py @@ -851,8 +851,6 @@ def test_tzoffset_is_not(): @pytest.mark.tzlocal @unittest.skipIf(IS_WIN, "requires Unix") -@unittest.skipUnless(TZEnvContext.tz_change_allowed(), - TZEnvContext.tz_change_disallowed_message()) class TzLocalNixTest(unittest.TestCase, TzFoldMixin): # This is a set of tests for `tzlocal()` on *nix systems @@ -962,8 +960,6 @@ def mark_tzlocal_nix(f): marks = [ pytest.mark.tzlocal, pytest.mark.skipif(IS_WIN, reason='requires Unix'), - pytest.mark.skipif(not TZEnvContext.tz_change_allowed, - reason=TZEnvContext.tz_change_disallowed_message()) ] for mark in reversed(marks): @@ -2070,8 +2066,6 @@ class TZTest(unittest.TestCase): datetime(2007, 8, 6, 2, 10, tzinfo=tz.tzstr("UTC-2"))) @unittest.skipIf(IS_WIN, "requires Unix") - @unittest.skipUnless(TZEnvContext.tz_change_allowed(), - TZEnvContext.tz_change_disallowed_message()) def testTZSetDoesntCorrupt(self): # if we start in non-UTC then tzset UTC make sure parse doesn't get # confused @@ -2254,8 +2248,6 @@ class TzWinTest(unittest.TestCase, TzWinFoldMixin): @unittest.skipUnless(IS_WIN, "Requires Windows") -@unittest.skipUnless(TZWinContext.tz_change_allowed(), - TZWinContext.tz_change_disallowed_message()) class TzWinLocalTest(unittest.TestCase, TzWinFoldMixin): def setUp(self): |