From 20e75120236d8749dc1f8b2b6cda3e9ae3b5bd22 Mon Sep 17 00:00:00 2001 From: John Kristensen Date: Mon, 7 Sep 2015 23:24:33 +1000 Subject: [PATCH] Work-around for pytest.mark.skipif() bug There is a pytest bug that can cause all test classes marked with the skipif() decorator that inherit a common class to be skipped if one of the skipif() conditions is True. See: https://github.com/pytest-dev/pytest/issues/568 --- test/test_dates.py | 8 ++++---- test/test_indexer.py | 11 +++++------ test/test_mailgw.py | 9 ++++----- test/test_mysql.py | 13 +++++-------- test/test_postgresql.py | 10 +++++----- 5 files changed, 23 insertions(+), 28 deletions(-) diff --git a/test/test_dates.py b/test/test_dates.py index 703a64cc..e0736e0e 100644 --- a/test/test_dates.py +++ b/test/test_dates.py @@ -25,13 +25,13 @@ from roundup.date import Date, Interval, Range, fixTimeOverflow, \ get_timezone +# FIX: workaround for a bug in pytest.mark.skipif(): +# https://github.com/pytest-dev/pytest/issues/568 try: import pytz - SKIP_PYTZ = False + skip_pytz = lambda func, *args, **kwargs: func except ImportError: - SKIP_PYTZ = True - -skip_pytz = pytest.mark.skipif(SKIP_PYTZ, reason="'pytz' not installed") + skip_pytz = pytest.skip("'pytz' not installed") class DateTestCase(unittest.TestCase): diff --git a/test/test_indexer.py b/test/test_indexer.py index 0180d274..8b29ac77 100644 --- a/test/test_indexer.py +++ b/test/test_indexer.py @@ -30,15 +30,14 @@ from .test_mysql import mysqlOpener, skip_mysql from test_sqlite import sqliteOpener +# FIX: workaround for a bug in pytest.mark.skipif(): +# https://github.com/pytest-dev/pytest/issues/568 try: import xapian - SKIP_XAPIAN = False + skip_xapian = lambda func, *args, **kwargs: func except ImportError: - SKIP_XAPIAN = True - -skip_xapian = pytest.mark.skipif( - SKIP_XAPIAN, - reason="Skipping Xapian indexer tests: 'xapian' not installed") + skip_xapian = pytest.skip( + "Skipping Xapian indexer tests: 'xapian' not installed") class db: diff --git a/test/test_mailgw.py b/test/test_mailgw.py index 5ff29b33..f3d43a28 100644 --- a/test/test_mailgw.py +++ b/test/test_mailgw.py @@ -17,14 +17,13 @@ import pytest +# FIX: workaround for a bug in pytest.mark.skipif(): +# https://github.com/pytest-dev/pytest/issues/568 try: import pyme, pyme.core - SKIP_PGP = False + skip_pgp = lambda func, *args, **kwargs: func except ImportError: - SKIP_PGP = True - -skip_pgp = pytest.mark.skipif( - SKIP_PGP, reason="Skipping PGP tests: 'pyme' not installed") + skip_pgp = pytest.skip("Skipping PGP tests: 'pyme' not installed") from cStringIO import StringIO diff --git a/test/test_mysql.py b/test/test_mysql.py index 3ae1ebee..4c7536a8 100644 --- a/test/test_mysql.py +++ b/test/test_mysql.py @@ -40,20 +40,17 @@ def nuke_database(self): self.module.db_nuke(config) +# FIX: workaround for a bug in pytest.mark.skipif(): +# https://github.com/pytest-dev/pytest/issues/568 if not have_backend('mysql'): - SKIP_MYSQL = True - SKIP_MYSQL_REASON = 'Skipping MySQL tests: not enabled' + skip_mysql = pytest.skip('Skipping MySQL tests: backend not available') else: try: import MySQLdb mysqlOpener.module.db_exists(config) - SKIP_MYSQL = False - SKIP_MYSQL_REASON = '' + skip_mysql = lambda func, *args, **kwargs: func except (MySQLdb.MySQLError, DatabaseError) as msg: - SKIP_MYSQL = True - SKIP_MYSQL_REASON = 'Skipping MySQL tests: %s' % str(msg) - -skip_mysql = pytest.mark.skipif(SKIP_MYSQL, reason=SKIP_MYSQL_REASON) + skip_mysql = pytest.skip('Skipping MySQL tests: %s' % str(msg)) @skip_mysql diff --git a/test/test_postgresql.py b/test/test_postgresql.py index e4a5d26a..2c796de5 100644 --- a/test/test_postgresql.py +++ b/test/test_postgresql.py @@ -26,13 +26,13 @@ from roundup.backends import get_backend, have_backend +# FIX: workaround for a bug in pytest.mark.skipif(): +# https://github.com/pytest-dev/pytest/issues/568 if not have_backend('postgresql'): - SKIP_POSTGRESQL = True + skip_postgresql = pytest.skip( + 'Skipping PostgreSQL tests: backend not available') else: - SKIP_POSTGRESQL = False - -skip_postgresql = pytest.mark.skipif( - SKIP_POSTGRESQL, reason='Skipping PostgreSQL tests: not enabled') + skip_postgresql = lambda func, *args, **kwargs: func class postgresqlOpener: