Skip to content

Commit

Permalink
TST: Refactor sql test inheritance
Browse files Browse the repository at this point in the history
Pytest wouldn't discover the tests in the same way as nose when

1. The base class inherits from `TestCase`, and
2. The base class doesn't start with `Test` (e.g. PandasSQLTest)
3. The parent class with test methods doesn't start with `Test` (
  e.g. _TestSQLAPI)

We solved this by moving the class inheriting from `TestCase` down a
level from `PandasSQLTest` to the many `TestSQL*` methods.
  • Loading branch information
TomAugspurger committed Feb 10, 2017
1 parent 3d6fcdc commit 9b5f2b2
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions pandas/io/tests/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def _close_conn(self):
pass


class PandasSQLTest(unittest.TestCase):
class PandasSQLTest(object):
"""
Base class with common private methods for SQLAlchemy and fallback cases.
Expand Down Expand Up @@ -839,7 +839,7 @@ def test_unicode_column_name(self):
df.to_sql('test_unicode', self.conn, index=False)


class TestSQLApi(SQLAlchemyMixIn, _TestSQLApi):
class TestSQLApi(SQLAlchemyMixIn, _TestSQLApi, unittest.TestCase):
"""
Test the public API as it would be used directly
Expand Down Expand Up @@ -1024,11 +1024,11 @@ def tearDown(self):
super(_EngineToConnMixin, self).tearDown()


class TestSQLApiConn(_EngineToConnMixin, TestSQLApi):
class TestSQLApiConn(_EngineToConnMixin, TestSQLApi, unittest.TestCase):
pass


class TestSQLiteFallbackApi(SQLiteMixIn, _TestSQLApi):
class TestSQLiteFallbackApi(SQLiteMixIn, _TestSQLApi, unittest.TestCase):
"""
Test the public sqlite connection fallback API
Expand Down Expand Up @@ -1875,34 +1875,39 @@ def test_schema_support(self):
tm.assert_frame_equal(res1, res2)


class TestMySQLAlchemy(_TestMySQLAlchemy, _TestSQLAlchemy):
class TestMySQLAlchemy(_TestMySQLAlchemy, _TestSQLAlchemy, unittest.TestCase):
pass


class TestMySQLAlchemyConn(_TestMySQLAlchemy, _TestSQLAlchemyConn):
class TestMySQLAlchemyConn(_TestMySQLAlchemy, _TestSQLAlchemyConn,
unittest.TestCase):
pass


class TestPostgreSQLAlchemy(_TestPostgreSQLAlchemy, _TestSQLAlchemy):
class TestPostgreSQLAlchemy(_TestPostgreSQLAlchemy, _TestSQLAlchemy,
unittest.TestCase):
pass


class TestPostgreSQLAlchemyConn(_TestPostgreSQLAlchemy, _TestSQLAlchemyConn):
class TestPostgreSQLAlchemyConn(_TestPostgreSQLAlchemy, _TestSQLAlchemyConn,
unittest.TestCase):
pass


class TestSQLiteAlchemy(_TestSQLiteAlchemy, _TestSQLAlchemy):
class TestSQLiteAlchemy(_TestSQLiteAlchemy, _TestSQLAlchemy,
unittest.TestCase):
pass


class TestSQLiteAlchemyConn(_TestSQLiteAlchemy, _TestSQLAlchemyConn):
class TestSQLiteAlchemyConn(_TestSQLiteAlchemy, _TestSQLAlchemyConn,
unittest.TestCase):
pass


# -----------------------------------------------------------------------------
# -- Test Sqlite / MySQL fallback

class TestSQLiteFallback(SQLiteMixIn, PandasSQLTest):
class TestSQLiteFallback(SQLiteMixIn, PandasSQLTest, unittest.TestCase):
"""
Test the fallback mode against an in-memory sqlite database.
Expand Down

0 comments on commit 9b5f2b2

Please sign in to comment.