Skip to Main Content
Python Testing with pytest
book

Python Testing with pytest

by Brian Okken
February 2022
Intermediate to advanced content levelIntermediate to advanced
274 pages
6h 28m
English
Pragmatic Bookshelf
Content preview from Python Testing with pytest

Using assert Statements

When you write test functions, the normal Python assert statement is your primary tool to communicate test failure. The simplicity of this within pytest is brilliant. It’s what drives a lot of developers to use pytest over other frameworks.

If you’ve used any other testing framework, you’ve probably seen various assert helper functions. For example, following is a list of a few of the assert forms and assert helper functions from unittest:

pytest

unittest

assert something

assertTrue(something)

assert not something

assertFalse(something)

assert a == b

assertEqual(a, b)

assert a != b

assertNotEqual(a, b)

assert a is None

assertIsNone(a)

assert a is not None

assertIsNotNone(a)

assert a <= b

assertLessEqual(a, b)

With pytest, you can ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Testing with pytest

Python Testing with pytest

Brian Okken

Publisher Resources

ISBN: 9781680509427Errata Page