Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
pytest Quick Start Guide

You're reading from   pytest Quick Start Guide Write better Python code with simple and maintainable tests

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher Packt
ISBN-13 9781789347562
Length 160 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Bruno Oliveira Bruno Oliveira
Author Profile Icon Bruno Oliveira
Bruno Oliveira
Arrow right icon
View More author details
Toc

To get the most out of this book

Here's a short list of what you will need to get started:

  • A desktop computer or laptop: pytest works in Linux, Windows, and macOS-X, so pick any system you prefer.
  • Python 3: All examples are written in Python 3.6, but they should work with Python 3.4 or up with minor alternations, if any. Most examples can also be ported to Python 2 with a little more effort, but Python 3 is strongly recommended.
  • Your favorite text editor or IDE to work on the code.
  • Be comfortable with Python: nothing too advanced is required, but Python concepts, such as the with statement and decorators are important to have.

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/pytest-Quick-Start-Guide. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Type this in your Command Prompt to create a virtualenv."

A block of code is set as follows:

 # contents of test_player_mechanics.py
def test_player_hit():
player = create_player()
assert player.health == 100
undead = create_undead()
undead.hit(player)
assert player.health == 80

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

def test_empty_name():
with pytest.raises(InvalidCharacterNameError):
create_character(name='', class_name='warrior')


def test_invalid_class_name():
with pytest.raises(InvalidClassNameError):
create_character(name='Solaire', class_name='mage')

Any command-line input or output is written as follows:

λ pip install pytest
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime