[PYTHON] How to unprefix the DB name used by pytest-django

Purpose

The database name used when running pytest-django is prefixed with "test_", but I want it to be the same as the database name normally used by model.

Unfortunately, the method wasn't written on the official site, so I read the source and looked it up.

The following are assumed as usage examples.

  1. Run the test using the data created in advance.
  2. Execute the API in django and check the data value updated by the API in test.

Example

settings.py


DATABASES = {
    'default': {
        'NAME': 'app_data',
    }

When py.test --create-db is executed with the above settings, test_app_data is created and used, but I want to use ʻapp_data`.

Log in to mysql and check the table


mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| app_data           |
| test_app_data      |
+--------------------+

What should I do?

If you write the following in DATABASES of settings.py, it's OK.

For django 1.8 and above

Added dict with 'TEST' as a key in the same row as 'NAME'. Specify the DB name in the dict with 'NAME' as the key.

settings.py


DATABASES = {
    'default': {
        'NAME': 'app_data',
        'TEST': {
            'NAME': 'app_data',
        }
    }

For django 1.7 or less

Specify the DB name using 'TEST_NAME' as a key in the same column as 'NAME'.

settings.py


DATABASES = {
    'default': {
        'NAME': 'app_data',
        'TEST_NAME': 'app_data',
    }

Recommended Posts

How to unprefix the DB name used by pytest-django
How to check the Java version used by Maven
How to get and set the NTP server name by DHCP
How to erase the characters output by Python
How to use the generator
How to use the decorator
How to increase the axis
How to start the program
How to switch the configuration file to be read by Python
How to test the attributes added by add_request_method of pyramid
How to use the zip function
How to use the optparse module
How to read the SNLI dataset
How to get the Python version
[Python] How to import the library
I tried to summarize the commands used by beginner engineers today
How to use the ConfigParser module
[Python Kivy] How to get the file path by dragging and dropping
How to easily switch the virtual environment created by Conda on Jupyter
Script to register the IP address used by wercker in Security Group
[Development environment] How to create a data set close to the production DB
I tried to summarize the Linux commands used by beginner engineers today-Part 1-
How to automatically notify by phone when the python system is down
How to sort by specifying a column in the Python Numpy array.
[Python] How to convert db file to csv
How to use the Spark ML pipeline
Qiita (1) How to write a code name
Try to face the integration by parts
python notes: Modularization: __name__ == How to use'__main__'
How to solve the bin packing problem
How to set the server time to Japanese time
How to manually update the AMP cache
[Linux] How to use the echo command
How to use the Linux grep command
How to get colored output to the console
How to operate Linux from the console
How to access the Datastore from the outside
How to use the IPython debugger (ipdb)
How to get the "name" of a field whose value is limited by the choice attribute in Django's model
python I don't know how to get the printer name that I usually use.
How to get the notebook name you are currently using in Google Colab
How to read all the classes contained in * .py in the directory specified by Python
[python] How to sort by the Nth Mth element of a multidimensional array
How to install a Python library that can be used by pharmaceutical companies
How to assign multiple values to the Matplotlib colorbar
How to calculate the volatility of a brand
[python] How to display list elements side by side
How to use the C library in Python
How to specify the launch browser for JupyterLab 3.0.0
How to use MkDocs for the first time
How to convert m4a acquired by iTunes to wav
How to specify the NIC to scan with amazon-dash
[Python] How to change the date format (display format)
How to set Django DB to mongodb visual studio 2019
[Django] How to get data by specifying SQL.
How to try the friends-of-friends algorithm with pyfof
How to use the graph drawing library Bokeh
How to print debug messages to the Django console
How to use the Google Cloud Translation API
How to operate Linux from the outside Procedure
How to use the NHK program guide API