Skip to content

Commit 8f5cbd2

Browse files
committed
Fix work-around for pytest markers bug
The initial work-around implemented was totally botched using 'pytest.skip' instead of 'pytest.mark.skip' which resulted in all tests in a file being completely ignored if any skip conditions that evaluated to true were declared or imported in the file. This work-around will not correctly display why all the tests have been skipped when using the '-rs' parameter. Only the first skip marker to taint a parent test class will be displayed (ie. if both xapian and mysql tests are being skipped, pytest will only output that tests are being skipped because xapian is not installed even though the mysql tests are also being skipped because mysql backend is not available). There also seems to be a bug in the current version of pytest being used in 'run_tests.py' (v2.8.4) that results in the skip not actually working when using 'pytest.mark.skip'. This does work correctly with the most recent release (v2.9.2), so the 'run_tests.py' script will need to be updated.
1 parent e6c6872 commit 8f5cbd2

File tree

7 files changed

+12
-11
lines changed

7 files changed

+12
-11
lines changed

test/test_dates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import pytz
3232
skip_pytz = lambda func, *args, **kwargs: func
3333
except ImportError:
34-
skip_pytz = pytest.skip("'pytz' not installed")
34+
skip_pytz = pytest.mark.skip(reason="'pytz' not installed")
3535

3636

3737
class DateTestCase(unittest.TestCase):

test/test_indexer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,17 @@
3636
import xapian
3737
skip_xapian = lambda func, *args, **kwargs: func
3838
except ImportError:
39-
skip_xapian = pytest.skip(
39+
skip_xapian = pytest.mark.skip(
4040
"Skipping Xapian indexer tests: 'xapian' not installed")
4141

4242
try:
4343
import whoosh
4444
skip_whoosh = lambda func, *args, **kwargs: func
4545
except ImportError:
46-
skip_whoosh = pytest.skip(
46+
skip_whoosh = pytest.mark.skip(
4747
"Skipping Whoosh indexer tests: 'whoosh' not installed")
4848

49+
4950
class db:
5051
class config(dict):
5152
DATABASE = 'test-index'

test/test_mailgw.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
import pyme, pyme.core
2424
skip_pgp = lambda func, *args, **kwargs: func
2525
except ImportError:
26-
skip_pgp = pytest.skip("Skipping PGP tests: 'pyme' not installed")
26+
skip_pgp = pytest.mark.skip(
27+
reason="Skipping PGP tests: 'pyme' not installed")
2728

2829

2930
from cStringIO import StringIO

test/test_mysql.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ def nuke_database(self):
4343
# FIX: workaround for a bug in pytest.mark.skipif():
4444
# https://github.com/pytest-dev/pytest/issues/568
4545
if not have_backend('mysql'):
46-
skip_mysql = pytest.skip('Skipping MySQL tests: backend not available')
46+
skip_mysql = pytest.mark.skip(
47+
reason='Skipping MySQL tests: backend not available')
4748
else:
4849
try:
4950
import MySQLdb
5051
mysqlOpener.module.db_exists(config)
5152
skip_mysql = lambda func, *args, **kwargs: func
5253
except (MySQLdb.MySQLError, DatabaseError) as msg:
53-
skip_mysql = pytest.skip('Skipping MySQL tests: %s' % str(msg))
54+
skip_mysql = pytest.mark.skip(
55+
reason='Skipping MySQL tests: %s' % str(msg))
5456

5557

5658
@skip_mysql

test/test_postgresql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
# FIX: workaround for a bug in pytest.mark.skipif():
3030
# https://github.com/pytest-dev/pytest/issues/568
3131
if not have_backend('postgresql'):
32-
skip_postgresql = pytest.skip(
33-
'Skipping PostgreSQL tests: backend not available')
32+
skip_postgresql = pytest.mark.skip(
33+
reason='Skipping PostgreSQL tests: backend not available')
3434
else:
3535
skip_postgresql = lambda func, *args, **kwargs: func
3636

test/test_userauditor.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import os, unittest, shutil
22

3-
import pytest
4-
53
from db_test_base import setupTracker
64
from .test_dates import skip_pytz
75

test/test_xmlrpc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import unittest, os, shutil, errno, sys, difflib, cgi, re
88

9-
import pytest
109
from xmlrpclib import MultiCall
1110
from roundup.cgi.exceptions import *
1211
from roundup import init, instance, password, hyperdb, date

0 commit comments

Comments
 (0)