Visual Testing with pytest
Test writing is productive and fun with PyCharm as a visual testing tool atop pytest.
Python developers love writing code. Tests? Not so much. Whether it’s the concepts of testing, or the interface of testing tools, testing is a chasm not all developers cross.
This tutorial aims to bring Python testing to the masses, taking a new approach to first contact with Python testing:
-
Let's make it fun and valuable
-
Visual testing using PyCharm
-
Driven by the popular pytest framework
-
Real-world scenario during the live building of a simple Python application
-
Shows how PyCharm can help you get into testing and development "flow"
Background on Testing
Introduce testing, pytest, and how it all fits into PyCharm, along with a scenario to work on.
Project Setup
Make a PyCharm project and virtual environment with dependencies, and configure PyCharm to use pytest.
Unit Tests
Write a simple test and run it in PyCharm's visual test runner.
Getting Into the TDD Flow
Setup your PyCharm project to help get into the flow of Test-Driven Development (TDD).
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.
Skipping Tests
During refactoring, use pytest's markers to ignore certain breaking tests.
Test Fixtures
Make your tests more focused by moving sample data to pytest fixtures.
Debugging During Testing
When writing tests, use the PyCharm "visual debugger" to interactively poke around in the context of a problem.
Testing for Exceptions
Write tests which ensure exceptions are raised when expected.