Issue: test_database uses production database instead of test database
Author: ajpen
State: closed
Created: 2016-09-12 04:15:22

I've the following code for testing:

```

from db import *
import unittest
from playhouse.test_utils import test_database


test_db = MySQLDatabase('testdb', 
    user='testuser', 
    password='testpass')


class DatabaseTestSuite(unittest.TestCase):

    def test_Admin(self):
        with test_database(test_db, (Admin), create_tables=True):

            Admin.create(username="testuser", 
                email="testuser@email.com")

            result = Admin.select().where(Admin.user == "testuser")

            unittest.assertIsNotNone(result)


if __name__ == '__main__':
    unittest.main()
```

Running the test produced this:

```
======================================================================
ERROR: test_Admin (__main__.DatabaseTestSuite)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "db/db_test.py", line 14, in test_Admin
    with test_database(test_db, (Admin), create_tables=True):
  File "/usr/local/lib/python2.7/dist-packages/playhouse/test_utils.py", line 21, in __enter__
    for m in self.models:
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 4723, in __iter__
    return iter(self.select())
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3149, in __iter__
    return iter(self.execute())
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3142, in execute
    self._qr = ResultWrapper(model_class, self._execute(), query_meta)
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2826, in _execute
    return self.database.execute_sql(sql, params, self.require_commit)
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3683, in execute_sql
    self.commit()
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3507, in __exit__
    reraise(new_type, new_type(*exc_args), traceback)
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3676, in execute_sql
    cursor.execute(sql, params or ())
  File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 835, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1019, in _read_query_result
    result.read()
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1302, in read
    first_packet = self.connection._read_packet()
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 981, in _read_packet
    packet.check_error()
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 393, in check_error
    err.raise_mysql_exception(self._data)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/err.py", line 107, in raise_mysql_exception
    raise errorclass(errno, errval)
ProgrammingError: (1146, u"Table 'db.admin' doesn't exist")

----------------------------------------------------------------------

```

The database 'db' refers to the production database and not the test database. The test should not be using the production database and only the test database. 

Here's my db module:

```

from peewee import * 
import datetime


# Database for the app
_Database = MySQLDatabase('db',
    host="localhost", 
    user='db_user', 
    password='db_pass')


# specifies the database all the other models
class BaseModel(Model):
    class Meta:
        database = _Database


# Database Objects

class Admin(BaseModel):

    # Admin unique indentifier field
    #id = PrimaryKeyField()

    username = CharField(unique=True, max_length=200)
    email = CharField(unique=True, max_length=500)
    created = DateTimeField(default=datetime.datetime.now)



```


This is an issue:

(Admin)

A 1-item tuple needs a trailing comma. Try again and let me know.


Have you been able to try your code with the change I suggested? This is the change:

``` python
    def test_Admin(self):
                                        # v
        with test_database(test_db, (Admin,), create_tables=True):
```


I just saw your comment. About to try it now.


It works now, thanks. 


I think I can make the code a little safer in the event of invalid input, so prod data doesn't get hurt. Very sorry an error wasn't raised.


That's fine. Happy to contribute. 


A suggestion for the [docs](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#test-utils)

Maybe change 

> models – a list of Model classes to use with the db

to 

> models – a tuple of Model classes to use with the db

Or add a note about the trailing comma for single element tuples. 


The trailing comma thing is just a part of Python, really. So beyond the scope of peewee that I'd feel compelled to add it anywhere a tuple is accepted, if I were going to start adding it here or there.


Hopefully, that'll help until you find something safer