Testing a book's code, part 6: Testing a Django project
MP 83: Testing a simple but nontrivial Django project, from a reader's perspective.
Note: This is the sixth post in a series about testing. This post will only be available to paid subscribers for the first 6 weeks. After that it will be available to everyone. Thank you to everyone who supports my ongoing work on Mostly Python.
The final project in Python Crash Course is a simple, but nontrivial Django project. It’s called Learning Log, and it lets users create their own online learning journals.
When testing a typical Django project, the focus is usually on testing the internal code in the project. I’m not really interested in that kind of testing here. Instead, I want to know that this project works on new versions of Django, which come out every 8(!) months. That’s a quick lifecycle, but it’s manageable because Django takes stability quite seriously.
In this post we’ll develop a single test function for the Learning Log project. It will create a copy of the project, build a separate virtual environment just for testing this project, and test whether the overall project functions as it’s supposed to.
Setting up the test environment
A Django project really needs its own virtual environment. I want this test to reflect how readers run the Learning Log project, so the test is going to make a fresh environment just for this project on every run. It’s then going to take the same actions a reader would when interacting with the project.
Copy project files to temp directory
Here’s the first part of test_django_project.py:
Keep reading with a 7-day free trial
Subscribe to Mostly Python to keep reading this post and get 7 days of free access to the full post archives.