From ad4c6a467359f0a8b6f386c8d1d864b4234fd5b1 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Wed, 13 Mar 2019 06:33:01 -0700 Subject: [PATCH] Use unittest 'skip' feature to skip mxDateTimeTests Rather than deleting, the class, use the skip feature. Provides a more informative message during test output. Never skip DatetimeTests as all supported Python environments have the datetime module builtin. --- tests/test_dates.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/tests/test_dates.py b/tests/test_dates.py index 95f40907..fdc28742 100755 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -447,11 +447,10 @@ class DatetimeTests(ConnectingTestCase, CommonDatetimeTestsMixin): self.assertRaises(psycopg2.NotSupportedError, cur.fetchone) -# Only run the datetime tests if psycopg was compiled with support. -if not hasattr(psycopg2.extensions, 'PYDATETIME'): - del DatetimeTests - - +@unittest.skipUnless( + hasattr(psycopg2._psycopg, 'MXDATETIME'), + 'Requires mx.DateTime support' +) class mxDateTimeTests(ConnectingTestCase, CommonDatetimeTestsMixin): """Tests for the mx.DateTime based date handling in psycopg2.""" @@ -626,14 +625,6 @@ class mxDateTimeTests(ConnectingTestCase, CommonDatetimeTestsMixin): self._test_type_roundtrip_array(DateTimeDeltaFrom(seconds=30)) -# Only run the mx.DateTime tests if psycopg was compiled with support. -try: - if not hasattr(psycopg2._psycopg, 'MXDATETIME'): - del mxDateTimeTests -except AttributeError: - del mxDateTimeTests - - class FromTicksTestCase(unittest.TestCase): # bug "TimestampFromTicks() throws ValueError (2-2.0.14)" # reported by Jozsef Szalay on 2010-05-06