开发者

Running the same tests with different configurations

I have some Python code abstract开发者_如何学Going the database and the business logic on it. This code is already covered by unit tests but now I need to test this code against different DBs (MySQL, SQLite, etc...)

What is the default pattern for passing the same set of tests with different configurations? My goal is making sure that that abstraction layer works as expected independently of the underlying database. If that could help, I'm using nosetests for running tests but it seems that it lacks the Suite Test concept

Best regards.


I like to use test fixtures for situations in which I have several similar tests. In Python, under Nose, I usually implement this as a common test module imported by other modules. For instance, I might use the following file structure:

db_fixtures.py:

import unittest

class BaseDB(unittest.TestCase):
  def testFirstOperation(self):
    self.db.query("Foo")
  def testSecondOperation(self):
    self.db.query("Blah")      

database_tests.py:

import db_fixtures

class SQliteTest(db_fixtures.BaseDB):
  def setUp(self):
    self.db = createSqliteconnection()

class MySQLTest(db_fixtures.BaseDB):
  def setUp(self):
    self.db = createMySQLconnection()

This will run all tests defined in BaseDB on both MySQL and SQlite. Note that I named db_fixtures.py in such a way that it won't be run by Nose.


Nose supports test suites just import and use unittest.TestSuite. In fact nose will happily run any tesys written using the standard lib's unittest module so tesys do not need to be written in the nose style to be discovered by the nose test runner.

However, I suspect you need morw than test suite support to do the kind of testing you are talking about but more detail about your application is necessary to really address that.


use --attrib plugin, and in the commadn line

1. nosetests -s -a 'sqlite'
2. nosetests -s -a 'mysql'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜