comparison test/test_mysql.py @ 5105:37d1e24fb941

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.
author John Kristensen <john@jerrykan.com>
date Mon, 27 Jun 2016 14:03:32 +1000
parents c977f3530944
children 43a1f7fe39f5
comparison
equal deleted inserted replaced
5104:ca3e56590fcd 5105:37d1e24fb941
41 41
42 42
43 # FIX: workaround for a bug in pytest.mark.skipif(): 43 # FIX: workaround for a bug in pytest.mark.skipif():
44 # https://github.com/pytest-dev/pytest/issues/568 44 # https://github.com/pytest-dev/pytest/issues/568
45 if not have_backend('mysql'): 45 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')
47 else: 48 else:
48 try: 49 try:
49 import MySQLdb 50 import MySQLdb
50 mysqlOpener.module.db_exists(config) 51 mysqlOpener.module.db_exists(config)
51 skip_mysql = lambda func, *args, **kwargs: func 52 skip_mysql = lambda func, *args, **kwargs: func
52 except (MySQLdb.MySQLError, DatabaseError) as msg: 53 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))
54 56
55 57
56 @skip_mysql 58 @skip_mysql
57 class mysqlDBTest(mysqlOpener, DBTest, unittest.TestCase): 59 class mysqlDBTest(mysqlOpener, DBTest, unittest.TestCase):
58 def setUp(self): 60 def setUp(self):

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