Skip to content

Commit b226acc

Browse files
committed
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: pytest-dev/pytest#568
1 parent 9e2df42 commit b226acc

File tree

5 files changed

+23
-28
lines changed

5 files changed

+23
-28
lines changed

test/test_dates.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
from roundup.date import Date, Interval, Range, fixTimeOverflow, \
2626
get_timezone
2727

28+
# FIX: workaround for a bug in pytest.mark.skipif():
29+
# https://github.com/pytest-dev/pytest/issues/568
2830
try:
2931
import pytz
30-
SKIP_PYTZ = False
32+
skip_pytz = lambda func, *args, **kwargs: func
3133
except ImportError:
32-
SKIP_PYTZ = True
33-
34-
skip_pytz = pytest.mark.skipif(SKIP_PYTZ, reason="'pytz' not installed")
34+
skip_pytz = pytest.skip("'pytz' not installed")
3535

3636

3737
class DateTestCase(unittest.TestCase):

test/test_indexer.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@
3030
from .test_mysql import mysqlOpener, skip_mysql
3131
from test_sqlite import sqliteOpener
3232

33+
# FIX: workaround for a bug in pytest.mark.skipif():
34+
# https://github.com/pytest-dev/pytest/issues/568
3335
try:
3436
import xapian
35-
SKIP_XAPIAN = False
37+
skip_xapian = lambda func, *args, **kwargs: func
3638
except ImportError:
37-
SKIP_XAPIAN = True
38-
39-
skip_xapian = pytest.mark.skipif(
40-
SKIP_XAPIAN,
41-
reason="Skipping Xapian indexer tests: 'xapian' not installed")
39+
skip_xapian = pytest.skip(
40+
"Skipping Xapian indexer tests: 'xapian' not installed")
4241

4342

4443
class db:

test/test_mailgw.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717

1818
import pytest
1919

20+
# FIX: workaround for a bug in pytest.mark.skipif():
21+
# https://github.com/pytest-dev/pytest/issues/568
2022
try:
2123
import pyme, pyme.core
22-
SKIP_PGP = False
24+
skip_pgp = lambda func, *args, **kwargs: func
2325
except ImportError:
24-
SKIP_PGP = True
25-
26-
skip_pgp = pytest.mark.skipif(
27-
SKIP_PGP, reason="Skipping PGP tests: 'pyme' not installed")
26+
skip_pgp = pytest.skip("Skipping PGP tests: 'pyme' not installed")
2827

2928

3029
from cStringIO import StringIO

test/test_mysql.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,17 @@ def nuke_database(self):
4040
self.module.db_nuke(config)
4141

4242

43+
# FIX: workaround for a bug in pytest.mark.skipif():
44+
# https://github.com/pytest-dev/pytest/issues/568
4345
if not have_backend('mysql'):
44-
SKIP_MYSQL = True
45-
SKIP_MYSQL_REASON = 'Skipping MySQL tests: not enabled'
46+
skip_mysql = pytest.skip('Skipping MySQL tests: backend not available')
4647
else:
4748
try:
4849
import MySQLdb
4950
mysqlOpener.module.db_exists(config)
50-
SKIP_MYSQL = False
51-
SKIP_MYSQL_REASON = ''
51+
skip_mysql = lambda func, *args, **kwargs: func
5252
except (MySQLdb.MySQLError, DatabaseError) as msg:
53-
SKIP_MYSQL = True
54-
SKIP_MYSQL_REASON = 'Skipping MySQL tests: %s' % str(msg)
55-
56-
skip_mysql = pytest.mark.skipif(SKIP_MYSQL, reason=SKIP_MYSQL_REASON)
53+
skip_mysql = pytest.skip('Skipping MySQL tests: %s' % str(msg))
5754

5855

5956
@skip_mysql

test/test_postgresql.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626

2727
from roundup.backends import get_backend, have_backend
2828

29+
# FIX: workaround for a bug in pytest.mark.skipif():
30+
# https://github.com/pytest-dev/pytest/issues/568
2931
if not have_backend('postgresql'):
30-
SKIP_POSTGRESQL = True
32+
skip_postgresql = pytest.skip(
33+
'Skipping PostgreSQL tests: backend not available')
3134
else:
32-
SKIP_POSTGRESQL = False
33-
34-
skip_postgresql = pytest.mark.skipif(
35-
SKIP_POSTGRESQL, reason='Skipping PostgreSQL tests: not enabled')
35+
skip_postgresql = lambda func, *args, **kwargs: func
3636

3737

3838
class postgresqlOpener:

0 commit comments

Comments
 (0)