Skip to content

Adding a DATABASES["default"]["TEST"]["NAME"] test database creation during pytest testing? #4725

Answered by HilbertSpecs
HilbertSpecs asked this question in Q&A
Discussion options

You must be logged in to vote

To anyone that might have a similar issue:

# did work 
DATABASES["default"]["TEST"] = env.db("TEST_DATABASE_URL")

The problem was occurring when I was unit testing functions that were hitting the database.

# originally in my pytest test.py file I was importing the function like so:
from parent_directory.python_file import function_hitting_database

# accessing the function being tested in the pytest unit test like so:
function_hitting_database()
# When I changed the import statement in pytest file to this:
import parent_directory

# And then accessed the function being tested in the pytest unit test like so:
parent_directory.python_file.function_hitting_database()

The pytest collection er…

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@HilbertSpecs
Comment options

Comment options

You must be logged in to vote
1 reply
@HilbertSpecs
Comment options

Answer selected by HilbertSpecs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants