Skip to content

Commit b45dba2

Browse files
committed
Add instructions for running database tests
1 parent 0020ab6 commit b45dba2

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ pip install django pytest-unmagic flake8
2525
2626
pytest
2727
flake8 --config=setup.cfg
28+
29+
# To run tests against postgres
30+
pip install psycopg2-binary
31+
psql -U username -h localhost -p 5432 -c 'create database django_cte;'
32+
export PG_DB_SETTINGS='{
33+
"ENGINE":"django.db.backends.postgresql_psycopg2",
34+
"NAME":"django_cte",
35+
"USER":"username",
36+
"PASSWORD":"password",
37+
"HOST":"localhost",
38+
"PORT":"5432"}'
39+
40+
# WARNING pytest will delete the test_django_cte database if it exists!
41+
DB_SETTINGS="$PG_DB_SETTINGS" pytest
2842
```
2943

3044
All feature and bug contributions are expected to be covered by tests.

tests/django_setup.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from __future__ import absolute_import
22
from __future__ import unicode_literals
33

4-
import sys
5-
64
from django.db import connection
75

86
from .models import KeyPair, Region, Order
@@ -16,13 +14,7 @@ def init_db():
1614
return
1715
is_initialized = True
1816

19-
# replace sys.stdout for prompt to delete database
20-
old_stdout = sys.stdout
21-
sys.stdout = sys.__stdout__
22-
try:
23-
connection.creation.create_test_db(verbosity=0)
24-
finally:
25-
sys.stdout = old_stdout
17+
connection.creation.create_test_db(verbosity=0, autoclobber=True)
2618

2719
setup_data()
2820

0 commit comments

Comments
 (0)