Skip to content

Commit

Permalink
Work-around for pytest.mark.skipif() bug
Browse files Browse the repository at this point in the history
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:

    pytest-dev/pytest#568
  • Loading branch information
jerrykan committed Jan 12, 2016
1 parent 07e6de8 commit 772ebcf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
8 changes: 4 additions & 4 deletions test/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 5 additions & 6 deletions test/test_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 4 additions & 5 deletions test/test_mailgw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions test/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/test_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 772ebcf

Please sign in to comment.