comparison test/test_mysql.py @ 5109:43a1f7fe39f5

Improved work-around for pytest markers bug The previous fix was only a partial solution. Any test class sharing a parent with, and appearing after, a skipped test class was being skipped (not just other test classes using the skip/skipif marker). Now only tests that should be skipped will be skipped, the rest should run as normal.
author John Kristensen <john@jerrykan.com>
date Tue, 28 Jun 2016 15:39:38 +1000
parents 37d1e24fb941
children efb34cbdba7c
comparison
equal deleted inserted replaced
5108:67fad01d2009 5109:43a1f7fe39f5
38 38
39 def nuke_database(self): 39 def nuke_database(self):
40 self.module.db_nuke(config) 40 self.module.db_nuke(config)
41 41
42 42
43 # FIX: workaround for a bug in pytest.mark.skipif(): 43 # FIX: workaround for a bug in pytest.mark.skip():
44 # https://github.com/pytest-dev/pytest/issues/568 44 # https://github.com/pytest-dev/pytest/issues/568
45 from .pytest_patcher import mark_class
46
45 if not have_backend('mysql'): 47 if not have_backend('mysql'):
46 skip_mysql = pytest.mark.skip( 48 skip_mysql = mark_class(pytest.mark.skip(
47 reason='Skipping MySQL tests: backend not available') 49 reason='Skipping MySQL tests: backend not available'))
48 else: 50 else:
49 try: 51 try:
50 import MySQLdb 52 import MySQLdb
51 mysqlOpener.module.db_exists(config) 53 mysqlOpener.module.db_exists(config)
52 skip_mysql = lambda func, *args, **kwargs: func 54 skip_mysql = lambda func, *args, **kwargs: func
53 except (MySQLdb.MySQLError, DatabaseError) as msg: 55 except (MySQLdb.MySQLError, DatabaseError) as msg:
54 skip_mysql = pytest.mark.skip( 56 skip_mysql = mark_class(pytest.mark.skip(
55 reason='Skipping MySQL tests: %s' % str(msg)) 57 reason='Skipping MySQL tests: %s' % str(msg)))
56 58
57 59
58 @skip_mysql 60 @skip_mysql
59 class mysqlDBTest(mysqlOpener, DBTest, unittest.TestCase): 61 class mysqlDBTest(mysqlOpener, DBTest, unittest.TestCase):
60 def setUp(self): 62 def setUp(self):

Roundup Issue Tracker: http://roundup-tracker.org/