From 9e9078af3e4da701214635aeb8bb9fc255f91ecf 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 | 6 ++---- test/test_indexer.py | 9 +++------ test/test_mailgw.py | 7 ++----- test/test_mysql.py | 11 +++-------- test/test_postgresql.py | 8 +++----- 5 files changed, 13 insertions(+), 28 deletions(-) diff --git a/test/test_dates.py b/test/test_dates.py index 703a64cc..22b81430 100644 --- a/test/test_dates.py +++ b/test/test_dates.py @@ -27,11 +27,9 @@ 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..8d46c7b5 100644 --- a/test/test_indexer.py +++ b/test/test_indexer.py @@ -32,13 +32,10 @@ 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..bcd2938e 100644 --- a/test/test_mailgw.py +++ b/test/test_mailgw.py @@ -19,12 +19,9 @@ 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..f4d292a4 100644 --- a/test/test_mysql.py +++ b/test/test_mysql.py @@ -41,19 +41,14 @@ def nuke_database(self): 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..55c63fde 100644 --- a/test/test_postgresql.py +++ b/test/test_postgresql.py @@ -27,12 +27,10 @@ from roundup.backends import get_backend, have_backend 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: