I run pytests using a test database with the following DB settings.
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'postgres', 'USER': 'something', 'PASSWORD': 'password', }, }
Using @ pytest.mark.django_db, my test functions access a database called "test_postgres" created for tests.
@pytest.mark.django_db def test_example(): from django.db import connection cur_ = connection.cursor() print cur_.db.settings_dict
outputs:
{'ENGINE': 'django.db.backends.postgresql_psycopg2', 'AUTOCOMMIT': True, 'ATOMIC_REQUESTS': False, 'NAME': 'test_postgres', 'TEST_MIRROR': None,...
but if I run the thread inside test_example:
def function_to_run(): from django.db import connection cur_ = connection.cursor logger.error(cur_.db.settings_dict) @pytest.mark.django_db def test_example(): p = multiprocessing.Process(target=function_to_run) p.start()
I see that in this thread the cursor uses a database called "postgres", which is not a testable database. Output:
{'ENGINE': 'django.db.backends.postgresql_psycopg2', 'AUTOCOMMIT': True, 'ATOMIC_REQUESTS': False, 'NAME': 'postgres', 'TEST_MIRROR': None,...
Is there a way to pass the argument of connecting the database to my stream from the original test function and tell my streaming program to use the same database name ('test_postgres') as my test function?