DEV Community

Cover image for Switch A Django Project To Use Pytest - Building SaaS #57
Matt Layman
Matt Layman

Posted on • Originally published at mattlayman.com

2 1

Switch A Django Project To Use Pytest - Building SaaS #57

In this episode, I replaced the default Django test runner to use pytest. We walked through installation, configuration, how to change tests, and the benefits that come from using pytest.

We started by looking at the current state of the test suite to provide a baseline to compare against. After that, I went to PyPI to find the version of pytest-django that we wanted to install. I added the package to my requirements-dev.txt and installed the update.

$ pip install -r requirements-dev.txt

I created a pytest.ini file and configured the package by setting the DJANGO_SETTINGS_MODULE. I initially typed the name of the setting incorrectly (forgetting the second S) so we debugged the failure case too.

Once pytest was running, we observed that all the tests passed. This behavior surprised me because I thought that the test would need to be marked to use a database. We dug into the details of the test execution to see which Python fixtures were used. We talked a bit about how fixtures worked.

I finished the stream by going through some tests and switching the assertion styles. We compared and contrasted assertions from unittest style tests versus pytest assertions.

This article first appeared on mattlayman.com.

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay