Title: Python Unit Tests at Hypothesis
Tags: Hypothesis, Python Unit Tests at Hypothesis
Alias: /post/python-unit-testing/
This is the index page for a series of posts about our approach to Python unit
tests at [Hypothesis](https://hypothes.is/):
- Running the Hypothesis Python Tests
- Debugging Failing Tests with pytest
- Writing Simple Python Unit Tests
- Arrange, Act, Assert
- Python Test Factories with factory_boy
- Testing that an Exception is Raised with pytest.raises
- Parametrizing Python Tests
- Basic pytest Fixtures
- Advanced pytest Fixtures
- Python’s unittest.mock
- Hypothesis’s patch Fixture
- sentinel: Unique Objects for Tests
- The Problem with Mocks
- usefixtures as a Class Decorator
- When and When Not to Use Mocks
- Matcher Objects in Python Tests
While this tutorial is based on Hypothesis's approach and the examples are
taken from Hypothesis's tests, most of it should be applicable to Python unit
testing generally.
These posts are aimed at intermediate Python developers, not complete beginners.
Basic knowledge of [Python](https://www.python.org/) programming and
[virtualenv](https://virtualenv.pypa.io/) are assumed, for example.
In a large, real-world project like Hypothesis the tests contain a lot of
things that might be unfamiliar - factories, `parametrize`, mocks, `sentinel`,
`patch`, `usefixtures` and [test method arguments that seem to come from nowhere](./python-unit-tests-at-hypothesis/_posts/2017-02-02-fixtures.md).
One of the aims of this tutorial is to introduce you to all these, so that you
can read the Hypothesis test code and understand what's going on.
Knowing how and when to use all of these tools will help you to write better
tests. We'll also cover a few more advanced aspects of writing **good tests**,
as opposed to bad ones, particularly when we talk about how to organize your
tests; the arrange, act, assert pattern and test naming; fixtures; and how and
when to use mocks.
Finally, we'll touch even less on the important but difficult topic of how to
design **good code** that works well and is easy to test.