diff test/test_mysql.py @ 5036:380d8d8b30a3

Replace existing run_tests.py script with a pytest script The existing run_test.py script is quite old, a bit restrictive, and doesn't always behave as documented. The pytest testing tool is mature, well documented, and maintained. The run_tests.py script is generating by installing py.test and running: py.tests --genscript=run_tests.py Note: to generate a script that is compatible with python2.6 the command needs to be run using python2.6
author John Kristensen <john@jerrykan.com>
date Thu, 20 Aug 2015 18:15:23 +1000
parents 63c79c0992ae
children 364c54991861
line wrap: on
line diff
--- a/test/test_mysql.py	Fri Aug 21 17:37:22 2015 +1000
+++ b/test/test_mysql.py	Thu Aug 20 18:15:23 2015 +1000
@@ -17,6 +17,7 @@
 
 import unittest, os, shutil, time, imp
 
+import pytest
 from roundup.hyperdb import DatabaseError
 from roundup.backends import get_backend, have_backend
 
@@ -39,24 +40,44 @@
         self.module.db_nuke(config)
 
 
+if not have_backend('mysql'):
+    SKIP_MYSQL = True
+    SKIP_MYSQL_REASON = 'Skipping MySQL tests: not enabled'
+else:
+    try:
+        import MySQLdb
+        mysqlOpener.module.db_exists(config)
+        SKIP_MYSQL = False
+        SKIP_MYSQL_REASON = ''
+    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
 class mysqlDBTest(mysqlOpener, DBTest, unittest.TestCase):
     def setUp(self):
         mysqlOpener.setUp(self)
         DBTest.setUp(self)
 
 
+@skip_mysql
 class mysqlROTest(mysqlOpener, ROTest, unittest.TestCase):
     def setUp(self):
         mysqlOpener.setUp(self)
         ROTest.setUp(self)
 
 
+@skip_mysql
 class mysqlSchemaTest(mysqlOpener, SchemaTest, unittest.TestCase):
     def setUp(self):
         mysqlOpener.setUp(self)
         SchemaTest.setUp(self)
 
 
+@skip_mysql
 class mysqlClassicInitTest(mysqlOpener, ClassicInitTest, unittest.TestCase):
     backend = 'mysql'
     def setUp(self):
@@ -67,6 +88,7 @@
         self.nuke_database()
 
 
+@skip_mysql
 class mysqlConcurrencyTest(mysqlOpener, ConcurrentDBTest, unittest.TestCase):
     backend = 'mysql'
     def setUp(self):
@@ -77,6 +99,7 @@
         self.nuke_database()
 
 
+@skip_mysql
 class mysqlHTMLItemTest(mysqlOpener, HTMLItemTest, unittest.TestCase):
     backend = 'mysql'
     def setUp(self):
@@ -87,6 +110,7 @@
         self.nuke_database()
 
 
+@skip_mysql
 class mysqlFilterCacheTest(mysqlOpener, FilterCacheTest, unittest.TestCase):
     backend = 'mysql'
     def setUp(self):
@@ -98,6 +122,7 @@
 
 
 from session_common import RDBMSTest
+@skip_mysql
 class mysqlSessionTest(mysqlOpener, RDBMSTest, unittest.TestCase):
     def setUp(self):
         mysqlOpener.setUp(self)

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