Faster Django tests in PyCharm¶
PyCharm notes¶
Problem¶
Pressing the green play triangle button is slow.
It runs python manage.py path_to_test
- drops and creates a new test database
- (slow 🐢)
Solution¶
We can update the Django tests
template to add the --keepdb
option
So that when you click on the green triangle, it will run
- Open the Run/Debug Configurations
- In the top right of PyCharm, click the box to the left of the green play button
- Click
Edit Configurations...
- Add the
--keepdb
option to the Django tests
Have an older version of PyCharm that doesn't match that screenshot?
Screenshot for PyCharm 2020.3
Apply migrations in the test database¶
Tests failing because your migrations aren't in the test database?
- Get the name of your test database
- test database has the same name as the
DATABASE_URL
in.env
with atest_
prefix - example
- database name is
my_db
- the test database is
test_my_db
- database name is
- test database has the same name as the
- Drop the test database
dropdb test_my_db
- Run a test
- a new database will be created with the migrations
Last update:
2023-04-24