Tips & Tricks Tutorials

Tutorial: Visual testing with pytest

If you are like many Python developers out there you LOVE writing code! Tests? Not so much. Whether it’s the concept of testing or the interface of testing tools, testing is a chasm not all developers cross. The Visual Testing with pytest tutorial aims to bring Python testing to the masses, taking a new approach to first contact with Python testing.

Join this journey with us and improve your testing skills in this 9-step tutorial!

The tutorial

As mentioned before, this tutorial was split into 9 steps. The idea is to make each step unique so you can watch and apply your learning as you go. Each tutorial step has a narrated video along with a detailed writeup, connected to working code.

Here’s an overview and below you can find a description for each step.

  • Step 1 – Background on Testing: Introduce testing, pytest, and how it all fits into PyCharm, along with a scenario to work on.
  • Step 2 – Project Setup: Make a PyCharm project and virtual environment with dependencies, then configure PyCharm to use pytest.
  • Step 3 – Hello Test: Write a simple test and run it in PyCharm’s visual test runner.
  • Step 4 – Getting Into the TDD Flow: Setup your PyCharm project to help get into the flow of Test-Driven Development (TDD).
  • Step 5 – Jump to Error: Writing code means writing broken code. Click a link in a traceback to open a file on the line of the error.
  • Step 6 – Skipping Tests: During refactoring, use pytest’s markers to ignore certain breaking tests.
  • Step 7 – Test Fixtures: Make your tests more focused by moving sample data to pytest fixtures.
  • Step 8 – Debugging During Testing: When writing tests, use the PyCharm “visual debugger” to interactively poke around in the context of a problem.
  • Step 9 – Testing Exceptions: Write tests that ensure exceptions are raised when expected.

About pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries. For more information about the pytest framework read their official documentation.

About the PyCharm Guide

Looking to level up your Python and PyCharm skills? The PyCharm Guide takes a visual approach, with tips, tutorials, and more.

image description