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](/guide/assets/thumbnail-4da37a35.png)
Background on Testing
Introduce testing, pytest, and how it all fits into PyCharm, along with a scenario to work on.
![Project Setup](/guide/assets/thumbnail-552f0ad9.png)
Project Setup
Make a PyCharm project and virtual environment with dependencies, and configure PyCharm to use pytest.
![Unit Tests](/guide/assets/thumbnail-f3f9205a.png)
Unit Tests
Write a simple test and run it in PyCharm's visual test runner.
![Getting Into the TDD Flow](/guide/assets/thumbnail-4312a25f.png)
Getting Into the TDD Flow
Setup your PyCharm project to help get into the flow of Test-Driven Development (TDD).
![Jump to Error](/guide/assets/thumbnail-251607ba.png)
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](/guide/assets/thumbnail-c616ff80.png)
Skipping Tests
During refactoring, use pytest's markers to ignore certain breaking tests.
![Test Fixtures](/guide/assets/thumbnail-9ace049a.png)
Test Fixtures
Make your tests more focused by moving sample data to pytest fixtures.
![Debugging During Testing](/guide/assets/thumbnail-eecf70ca.png)
Debugging During Testing
When writing tests, use the PyCharm "visual debugger" to interactively poke around in the context of a problem.
![Testing for Exceptions](/guide/assets/thumbnail-0f6ef4a5.png)
Testing for Exceptions
Write tests which ensure exceptions are raised when expected.